I''ve got a couple of before_filter methods which are partially
redundant. I''d like to merge them into one and just look at a passed
parameter to tell which path to take. So instead of doing this...
before_filter :authorize
OR
before_filter :authorize_admin
I''d like to be able to do...
before_filter :authorize
OR
before_filter :authorize("admin")
So far, I haven''t been successful in doing this. Is this possible? Any
tips?
Thanks,
Alison
Try
before_filter :authorize
before_filter lambda{ authorize("admin") }
But the second one might have some performance issues.
Kent.
On Wednesday 07 December 2005 14:15, Alison Rowland
wrote:> I''ve got a couple of before_filter methods which are partially
> redundant. I''d like to merge them into one and just look at a
passed
> parameter to tell which path to take. So instead of doing this...
>
> before_filter :authorize
> OR
> before_filter :authorize_admin
>
> I''d like to be able to do...
>
> before_filter :authorize
> OR
> before_filter :authorize("admin")
>
> So far, I haven''t been successful in doing this. Is this possible?
Any
> tips?
>
> Thanks,
> Alison
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
Can you use the session to store the parameter so you don''t have to
pass
anything?
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Alison Rowland
Sent: Wednesday, December 07, 2005 1:15 PM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] Passing a parameter to a before_filter method
I''ve got a couple of before_filter methods which are partially
redundant. I''d like to merge them into one and just look at a passed
parameter to tell which path to take. So instead of doing this...
before_filter :authorize
OR
before_filter :authorize_admin
I''d like to be able to do...
before_filter :authorize
OR
before_filter :authorize("admin")
So far, I haven''t been successful in doing this. Is this possible? Any
tips?
Thanks,
Alison
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
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
Actually I got the lambda version wrong. It should look like
before_filter lambda{|controller| controller.authorize("admin") }
Kent.
On Thursday 08 December 2005 07:32, Alison Rowland
wrote:> 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
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
Kent Sibilev wrote:> Actually I got the lambda version wrong. It should look like > > before_filter lambda{|controller| controller.authorize("admin") } > > Kent. > > On Thursday 08 December 2005 07:32, Alison Rowland wrote: > >>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.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>> >>--Alison