Forum: Ruby on Rails Passing parameters to before_filter methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0cffe192be5af0fca5bdbd73cf6c82ea?d=identicon&s=25 Ian J Cottee (Guest)
on 2005-12-15 08:25
(Received via mailing list)
I have a method that checks for a given role. I want to write
something in my controllers like

	before_filter :check_roles('admin')

Which will ensure the current user has the admin role. Is it possible
to pass parameters in this way?

Ian
5ceea097a3b29cb6a5da6705926410f4?d=identicon&s=25 Gerret Apelt (Guest)
on 2005-12-15 09:40
(Received via mailing list)
Hi Ian, I do this:

def Controller < ActionController::Base
  before_filter { |c| c.role_required 'admin' }

  def role_required(role)
    ...
  end
end

cheers,
Gerret
0cffe192be5af0fca5bdbd73cf6c82ea?d=identicon&s=25 Ian J Cottee (Guest)
on 2005-12-15 23:43
(Received via mailing list)
Gerret

Thanks *very* much for that. Think it would have taken me a while to
figure that one out!

Ian
This topic is locked and can not be replied to.