RE: Passing a parameter to a before_filter method


#1

Can you use the session to store the parameter so you don’t have to pass
anything?


#2

Thanks for the replies. The lambda didn’t want to work. I got a no
method error. That was with the called function in application.rb and
the before_filter call in another file, which was a sub-sub-class of
application.rb.

I ended up reorganizing my one or two bigger functions into three
really small functions, and got things working.

–Alison


#3

Actually I got the lambda version wrong. It should look like

before_filter lambda{|controller| controller.authorize(“admin”) }

Kent.


#4

Kent S. wrote:

the before_filter call in another file, which was a sub-sub-class of
application.rb.

I ended up reorganizing my one or two bigger functions into three
really small functions, and got things working.

One other point - Rails is single threaded, so you can use class
variables or globals to hold state within the life of a single request.
I’ve seen this given as the answer to “how to make the current user
accessible to models”.

regards

Justin