Notes posted by abriening
RSS feed
1 thank
Re: Passing parameters to before_filter
I am not sure I get your “method 1” alec-c4; won’t that define the method each time the before_filter is called? Why not just define the method in the controller?
You can pass parameters or call protected methods with instance_eval:
before_filter :only => :show do |controller| controller.instance_eval do redirect_to edit_object_path(params[:id]) end end

6 thanks
Extend with an anonymous module
You can extend with an anonymous module for one-off cases that won’t be repeated:
belongs_to :container, :polymorphic => true, :extend => ( Module.new do def find_target ... end end )
The parentheses are important, will fail silently without them.