Skip to content

Instantly share code, notes, and snippets.

@Hampei
Last active August 29, 2015 14:06
Show Gist options
  • Save Hampei/0b9605e2c659eb23726f to your computer and use it in GitHub Desktop.
Save Hampei/0b9605e2c659eb23726f to your computer and use it in GitHub Desktop.
active interaction aware responder
# 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