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. :wink:

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? :slight_smile:

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