On Mar 8, 12:45 am, "Todd A. Jacobs"
<codegnome.consult...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ve googled around enough to see that this is a common issue, but
> haven''t found a definitive answer on how to access a value from
the
> params hash in a before_filter. I''m currently trying this:
>
> before_filter :only => [:create, :update, :destroy] do |controller|
> controller.bounce_if_unauthorized params[:token]
> end
If you use the block form of before_filter then self isn''t the
controller instance - params[:token] goes nowhere.
controller.params[:token] would work (if params is public - I don''t
recall), or you could do
before_filter :blah, :only => ...
def blah
unless params[:token] == ...
...
end
end
Fred>
> with the following in application_controller.rb:
>
> protected
> def bounce_if_unauthorized token
> puts token
> redirect_to root_path,
> :alert => ''You are not authorized.'' unless token
== ''abcde''
> end
>
> but the equality is never true. Meanwhile, the verify method mentioned
> athttp://guides.rubyonrails.org/action_controller_overview.html#filters
> is no longer listed in the API, so that''s probably not the way to
go
> either.
>
> How can I create a before_filter based on an element of the params
> hash?
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.