before_filter with dynamic information

Posted by Lauren on Stack Overflow See other posts from Stack Overflow or by Lauren
Published on 2009-09-16T15:35:50Z Indexed on 2010/04/15 18:03 UTC
Read the original article Hit count: 138

Hi I am trying to add a filter to a controller that is based on a certain role (using role_requirement) and then on the company_id that each user has.

So basically I need something like this:

require_role "company" ** This is working fine
  before_filter :company_required

def company_required
  unless current_user.company_id == Company.find(params[:id])    
end

end

The error I am receiving undefined method `company_id' for nil:NilClass

I would appreciate any guidance. Thanks

© Stack Overflow or respective owner

Related posts about before-filter

Related posts about ruby-on-rails