Search code examples
ruby-on-railscontrollerauthorizationrolesbefore-filter

before_filter checking multiple roles


In application_controller I have the following method:

  def authorized_for_roles(*roles)
    roles.each{|role_name| return true if current_user.has_role?(role_name)}
    false
  end

In one of my controllers, I have

private

  def authorize_administration
    authorized_for_roles :administrator
  end

I am calling authorize_administration in my before_filter. Currently getting 'undefined method roles" error. Can someone tell me where I've gone wrong? the current_user is valid/defined, and the role can be checked.

Thanks


Solution

  • Is the error really in the authorized_for_roles def, or perhaps in the User model? Did you define has_many :roles for User?