Sha256: 955f5c86e0f446b332714e9b6cf36bb477cde8612e6a5fbaba452a63e5200b64

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

class Admin::RolesController < ApplicationController
  include TheRole::Controller
  layout  TheRole.config.layout.to_s

  before_filter :login_required
  before_filter :role_required

  before_filter :role_find,      only: [:edit, :update, :destroy, :change]
  before_filter :owner_required, only: [:edit, :update, :destroy, :change]

  def index
    @roles = Role.all.order('created_at ASC')
  end

  def new
    @role = Role.new
  end

  def edit; end

  def create
    @role = Role.new role_params

    if @role.save
      flash[:notice] = t 'the_role.role_created'
      redirect_to_edit
    else
      render :action => :new
    end
  end

  def update
    if @role.update_role params[:role][:the_role]
      flash[:notice] = t 'the_role.role_updated'
      redirect_to_edit
    else
      render :action => :edit
    end
  end

  def change
    if @role.update_attributes!(role_params)
      flash[:notice] = t 'the_role.role_updated'
      redirect_to_edit
    else
      render :action => :edit
    end
  end

  def destroy
    @role.destroy
    flash[:notice] = t 'the_role.role_deleted'
    redirect_to admin_roles_url
  end

  protected

  def role_params
    params.require(:role).permit(:name, :title, :description, :the_role)
  end

  def role_find
    @role = Role.find params[:id]

    # TheRole: You should define OWNER CHECK OBJECT
    # When editable object was found
    @owner_check_object = @role
  end

  def redirect_to_edit
    redirect_to edit_admin_role_path @role
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
the_role-2.5.2 app/controllers/admin/roles_controller.rb
the_role-2.5.1 app/controllers/admin/roles_controller.rb
the_role-2.5 app/controllers/admin/roles_controller.rb
the_role-2.4 app/controllers/admin/roles_controller.rb
the_role-2.3 app/controllers/admin/roles_controller.rb