Sha256: ac2758d0d6b56f405736f13d18b753591c5bfcb7435aeb12d33cc9c979e627c2

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

module ConfigManager
  class AdminsController < ConfigManager::ApplicationController
    # GET /admins
    def index
      page = params[:page] || 1
      per_page = params[:page] ? (params[:per_page] || PER_PAGE) : nil
      @admins = Admin.page(page).per(per_page)
    end

    # GET /admins/new
    def new
      @admin = Admin.new admin_params
    end

    # GET /admin/:id/edit
    def edit
      @admin = Admin.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      flash[:error] = "Admin with id=#{params[:id]} couldn't be found"
      redirect_to admins_path
    end

    # POST /admin/:id/update
    def update
      @admin = Admin.find(params[:id])
      if @admin.update_attributes admin_params
      	flash[:notice] = "Admin user #{@admin.email} successfully updated"
      else
      	render "edit"
      end
    rescue ActiveRecord::RecordNotFound
      flash[:error] = "Admin with id=#{params[:id]} couldn't be found"
      redirect_to admins_path
    end

    # POST /admins
    def create
      @admin = Admin.new admin_params
      if @admin.save
        flash[:notice] = "New admin user #{@admin.email} successfully created"
        redirect_to admins_path
      else
        render "new"
      end
    end

    # DELETE /admin/:id
    def destroy
      @admin = Admin.find(params[:id])
      @admin.destroy
      redirect_to admins_path
    rescue ActiveRecord::RecordNotFound
      flash[:error] = "Admin with id=#{params[:id]} couldn't be found"
      redirect_to admins_path
    end
      
  private
    def admin_params
      if strong_parameters?  
        params[:admin] && params[:admin].permit(:email, 
                                                :password, 
                                                :password_confirmation) 
      else
        params[:admin]
      end
    end

    def strong_parameters?
      Rails::VERSION::MAJOR >= 4
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
config_manager-1.0.4 app/controllers/config_manager/admins_controller.rb
config_manager-1.0.3 app/controllers/config_manager/admins_controller.rb
config_manager-1.0.2 app/controllers/config_manager/admins_controller.rb
config_manager-1.0.0 app/controllers/config_manager/admins_controller.rb
config_manager-0.0.10 app/controllers/config_manager/admins_controller.rb
config_manager-0.0.9 app/controllers/config_manager/admins_controller.rb
config_manager-0.0.8 app/controllers/config_manager/admins_controller.rb
config_manager-0.0.7 app/controllers/config_manager/admins_controller.rb