ruby on rails - respond_to in after_filter -
i dry controllers placing reoccurring code in before , after filters. in current project, every action has same respond_to
block:
respond_to |wants| wants.html wants.js { render :layout => "transition" } end
i placed in after_filter
so:
after_filter :respond_to_html_or_transition
but leads error:
render and/or redirect called multiple times in action. please note may call render or redirect, , @ once per action. note neither redirect nor render terminate execution of action, if want exit action after redirecting, need "redirect_to(...) , return".
this happens when there no explicit respond_to
or redirect
within action. i'm assuming happens because rails (for lack of explicit respond_to
call) makes educated guess , creates own respond_to
before after_filter
. if that's case, there way me keep rails doing , instead use block in after_filter
?
what trying accomplish not possible after_filter. after filter deals rendered action. @ point, render have completed (either explicit or implicit render), calling render result in double call.
you can extract code logic in method , call method. alternative make actions alias of single action, assuming body of actions can handled single method.
last not least, can write custom action responder , replace default 1 of controller setting
self.responder = customactionresponder
Comments
Post a Comment