Tutorial :How do I redirect multiple actions to a single action while maintaining DRY?


I have an OptionsController, which contains an action account. The corresponding view has three forms, which post to three different actions, update_profile, update_user and change_password. Each action runs and then should redirect back to action, where the view is set up again and rendered.

I was trying to be DRY and create an after_filter to do the redirect:

after_filter( :only => [:change_password, :update_profile, :update_user] ) do |controller|    controller.send(:redirect_to, :action => :account)  end  

However, this doesn't seem to get called; rather, the action complains that its view cannot be found.

Template is missing  Missing template options/update_user.erb in view path app/views  

Is there any way I can do this in a DRY way, or should I just be sticking the redirect_to call in each of the three actions?


just put the redirect_to call in each of the actions. There is a fine line between DRY and unintelligible magic. I feel like trying to do something like an after_filter or anything else that nonobviously shatters the expected behavior of an action is probably too much magic.


It's my understanding that after filters are run after the response is sent to the client, meaning after any render or redirects occur, which is why you're seeing that error. They are intended to let you do things like log data, or benchmark or close connections or any other type of cleanup you have

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »