I like to dry my controllers by placing reoccurring code in before and after filters. In my current project, every action has the same respond_to
block:
respond_to do |wants|
wants.html
wants.js { render :layout => "transition" }
end
I placed this in an after_filter
like so:
after_filter :respond_to_html_or_transition
But it leads to this error:
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
This happens even when there is no explicit respond_to
or redirect
within the action. I'm assuming this happens because Rails (for lack of an explicit respond_to
call) makes an educated guess and creates its own respond_to
before the after_filter
. If that's the case, is there any way for me to keep Rails from doing that and instead use the block in the after_filter
?