Sha256: df13c559bf6d93d8ce1dfa17b5fe9a2eb53ae88813942ee7941e9a16df04a563

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

module Gaku
  class Admin::SchoolsController < Admin::BaseController

    load_and_authorize_resource class: School

    respond_to :js, :html

    inherit_resources

    before_filter :count, only: %i(create destroy index)
    before_filter :master_school, only: %i(index school_details edit_master)

    def school_details
      @school = @master_school
      render :show, layout: 'gaku/layouts/show'
    end

    def edit_master
      render :edit_master, layout: 'gaku/layouts/show'
    end

    def update
      @school = School.find(params[:id])
      super do |format|
        if params[:school][:picture]
          format.html do
            redirect_to [:admin, @school],
                        notice: t(:'notice.uploaded', resource: t(:'picture'))
          end
        else
          format.js { render }
         end
      end
    end

    protected

    def resource_params
      return [] if request.get?
      [params.require(:school).permit(attributes)]
    end

    private

    def master_school
      @master_school = School.primary
    end

    def count
      @count = School.count
    end

    def attributes
      [:name, :primary, :slogan, :description, :founded, :principal, :vice_principal, :grades, :code, { levels_attributes: [ :name, :'_destroy', :id ] }, :picture ]
    end

  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
gaku_core-0.0.3 app/controllers/gaku/admin/schools_controller.rb
gaku-0.0.3 core/app/controllers/gaku/admin/schools_controller.rb
gaku-0.0.2 core/app/controllers/gaku/admin/schools_controller.rb
gaku_core-0.0.2 app/controllers/gaku/admin/schools_controller.rb
gaku-0.0.1 core/app/controllers/gaku/admin/schools_controller.rb
gaku_core-0.0.1 app/controllers/gaku/admin/schools_controller.rb