josh
September 30, 2006, 7:33pm
1
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
josh
September 30, 2006, 9:37pm
2
Joshua M. wrote:
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.
josh
September 30, 2006, 10:34pm
3
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.