Sha256: e5b6aca4493882a4b66881c42752747ddb4d70854f133ba960cd4d1c8935de6f

Contents?: true

Size: 1.57 KB

Versions: 16

Compression:

Stored size: 1.57 KB

Contents

module Gaku
  class SemesterConnectorsController < GakuController

    respond_to :js, only: %i( new create edit update destroy )

    before_action :set_semesterable
    before_action :set_semester_connector, only: %i( edit update destroy)
    before_action :set_semesters, only: %i( new edit )

    def new
      @semester_connector = @semesterable.semester_connectors.new
      respond_with @semester_connector
    end

    def create
      @semester_connector = @semesterable.semester_connectors.build(semester_connector_params)
      @semester_connector.save
      set_count
      respond_with @semester_connector
    end

    def edit
      respond_with @semester_connector
    end

    def update
      @semester_connector.update(semester_connector_params)
      respond_with @semester_connector
    end

    def destroy
      @semester_connector.destroy
      set_count
      respond_with @semester_connector
    end

    private

    def set_semesterable
      resource, id = request.path.split('/')[1, 2]
      @semesterable = resource.insert(0, 'gaku/').pluralize.classify.constantize.find(id)
      @semesterable_resource = @semesterable.class.to_s.demodulize.underscore.dasherize
    end

    def set_semester_connector
      @semester_connector = SemesterConnector.find(params[:id])
    end

    def semester_connector_params
      params.require(:semester_connector).permit(attributes)
    end

    def attributes
      %i( semester_id )
    end

    def set_count
      @count = @semesterable.semesters.count
    end

    def set_semesters
      @semesters = Semester.all
    end

  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
gaku_frontend-0.3.0 app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.3.0.pre.4 app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.3.0.pre.3 app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.3.0.pre.2 app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.3.0.pre.1 app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.3.0.pre.0 app/controllers/gaku/semester_connectors_controller.rb
gaku-0.2.4 frontend/app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.2.4 app/controllers/gaku/semester_connectors_controller.rb
gaku-0.2.3 frontend/app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.2.3 app/controllers/gaku/semester_connectors_controller.rb
gaku-0.2.2 frontend/app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.2.2 app/controllers/gaku/semester_connectors_controller.rb
gaku-0.2.1 frontend/app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.2.1 app/controllers/gaku/semester_connectors_controller.rb
gaku-0.2.0 frontend/app/controllers/gaku/semester_connectors_controller.rb
gaku_frontend-0.2.0 app/controllers/gaku/semester_connectors_controller.rb