Last active
August 29, 2015 14:06
-
-
Save Hampei/4ebe71928e05ead5bb78 to your computer and use it in GitHub Desktop.
xhr aware responder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will render the the show method instead of redirecting when the action is an ajax request. | |
# Also adds an options xhr_show to render instead of show. | |
class XhrAwareResponder < ActionController::Responder | |
protected | |
def navigation_behavior(error) | |
if get? | |
raise error | |
elsif has_errors? && default_action | |
render action: default_action, layout: options[:layout] | |
elsif controller.request.xhr? | |
render action: options[:xhr_show] || :show, layout: options[:layout] | |
else | |
redirect_to navigation_location | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment