Last active
August 29, 2015 14:06
-
-
Save Hampei/0b9605e2c659eb23726f to your computer and use it in GitHub Desktop.
active interaction 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
# For json and xml, will render the result if no errors where present. | |
# otherwise will just render the interaction, containing things like {'errors' => {'attr' => ['invalid']}} | |
class ActiveInteractionAwareResponder < ActionController::Responder | |
def to_format | |
if resource.is_a?(ActiveInteraction::Base) | |
if resource.errors.empty? | |
@resource = resource.result | |
@resources[-1] = @resource | |
end | |
end | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment