Module: Challah::Rolls::Controller::ClassMethods

Defined in:
lib/challah/rolls/controller.rb

Instance Method Summary collapse

Instance Method Details

#restrict_to_permission(permission_key, options = {}) ⇒ Object Also known as: permission_required

Restrict the current controller to the given permission key. All actions in the controller will be restricted unless otherwise stated. All normal options for a before_filter are observed.

If the current user does not have the given permission key, they are shown the access denied message.

Examples:

class YourController < ApplicationController
  restrict_to_permission :manage_users

  # ...
end

Restrict only the given actions

class YourOtherController < ApplicationController
  restrict_to_permission :manage_users, :only => [ :create, :update, :destroy ]

  # ...
end

Parameters:

  • permission_key (String, Symbol)

    The permission to restrict action(s) to.



34
35
36
37
38
39
40
# File 'lib/challah/rolls/controller.rb', line 34

def restrict_to_permission(permission_key, options = {})
  before_filter(options) do |controller|
    unless controller.send(:has, permission_key)
      access_denied!
    end
  end
end