Module: Permit::ControllerExtensions::PermitClassMethods

Defined in:
lib/permit/controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) permit(options = {}, &block)

Creates a new block of Permit authorization rules, and sets the before filter to run them. The order of deny and allow rules do not matter. deny rules will always be run first, and evaluation terminates on the first match.

Examples:

permit do
  deny :developer, :from => :all, :unless => Proc.new {(8..17).include?(Time.now.hour)}
  allow :person, :who => :is_member, :of => :team, :to => :read
  allow [:project_manager, :developer], :on => :project, :to => :all
end

Parameters:

  • options (Hash) (defaults to: {})

    options to use when evaluating this block of authorizations.

  • &block (Block)

    the block containing the authorization rules. See PermitRules#allow and PermitRules#deny for the syntax for the respective types of rules.

Options Hash (options):



36
37
38
39
40
41
# File 'lib/permit/controller.rb', line 36

def permit(options = {}, &block)
  rules = PermitRules.new(Rails.logger, options)
  rules.instance_eval(&block) if block_given?
  self.permit_rules = rules
  set_permit_before_filter
end