Hi all I''d like to put a block after a before_filter instead of calling a separate method because I think it''s looking cooler. ;-) before_filter :only => [:new, :create] do |controller| flash[:notice] = "That is not allowed!." redirect_to :referer end Sadly this doesn''t work: ndefined local variable or method `flash'' for SchmuckSeitenController:Class I tried it with controller.flash, but then Rails tells me it is protected. Is there a way to access flash? :-) Thanks Josh -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Sep-30 19:31 UTC
Re: Access protected flash in block of before_filter?
Joshua Muheim wrote:> I''d like to put a block after a before_filter instead of calling a > separate method because I think it''s looking cooler. ;-) > > before_filter :only => [:new, :create] do |controller| > flash[:notice] = "That is not allowed!." > redirect_to :referer > end > > Sadly this doesn''t work: > > ndefined local variable or method `flash'' for > SchmuckSeitenController:Class > > I tried it with controller.flash, but then Rails tells me it is > protected. > Is there a way to access flash? :-)You can wrap your filter body in a controller.instance_eval block. But this is really a job for verify: http://api.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> But this is really a job for verify: > http://api.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html > > -- > We develop, watch us RoR, in numbers too big to ignore.Thanks, mate. I tried it the following way, but it doesn''t work: verify :only => [:new, :create], :add_flash => {:notice => ''Creation is deactivated.''}, :redirect_to => :back I want to prevent the user from creating a new object, but maybe later I will allow it to the user. So I just want to make sure he can''t access the new and create methods. -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---