Method: SimonSays::Authorizer::ClassMethods#find_and_authorize

Defined in:
lib/simon_says/authorizer.rb

#find_and_authorize(resource, *roles) ⇒ Object

Find and authorize a resource.

Parameters:

  • resource (Symbol, String)

    name of resource to find

  • roles (Array<Symbol, String>)

    one or more role symbols or strings

  • opts (Hash)

    before_action and finder options

  • opts (Symbol)

    :from corresponds to an instance variable or method that returns an ActiveRecord scope or model instance. If the object respond_to? to the pluralized resource name it is called and used as the finder scope. This makes it easy to handle finding resource through associations.

  • opts (Symbol)

    :find_attribute attribute resource is found by; by default, :id is used

  • opts (Symbol)

    :param_key params key for resource query; by default, :id is used

  • opts (Symbol)

    :through through model to use when finding resource

  • opts (Symbol)

    :namespace resource namespace

See Also:



48
49
50
51
52
53
54
55
56
# File 'lib/simon_says/authorizer.rb', line 48

def find_and_authorize(resource, *roles)
  opts = roles.extract_options!

  before_action(action_options(opts)) do
    find_resource resource, opts

    authorize roles, opts unless roles.empty?
  end
end