Hi --
On 3/20/07, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> I want to put a before_filter in application.rb, as follows:
>
> before_filter :do_something, :except_controller => [:admin]
>
> def do_something(options)
> options.stringify_keys!
> unless options[:except_controller].include?(controller_name)
> # do something useful
> end
> end
>
> Where I''m blocking is on how to get the
''options'' data in the do_something
> method. I think I can write this as:
The way I''ve done this in the past, which may or may not be the
slickest way to do it, is along the lines of:
class MyController < ApplicationController
before_filter :only => "whatever" do |controller|
controller.some_method(1,2,3)
end
def some_method(a,b,c)
...
end
end
The proc has the controller object itself yielded to it, so you can
then call the method on that object with whatever arguments you need.
The particular case you''ve got, where you seem to be testing for
whether this controller needs a particular filter, looks like it would
probably better handled with skip_before_filter and friends. But
anyway, you can grab the controller object and call methods on it
directly.
David
--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---