79790144

Date: 2025-10-14 12:09:27
Score: 2.5
Natty:
Report link

Just in case anyone stumbles upon this same issue, respond_with tries to build the location HTTP header when responding to a POST (create) action. When you pass an object that is not an ActiveRecord instance (or doesn't respond to #to_model), it will fail. It may also fail occasionally due to naming issues. I believe internally it uses the polymorphic_url or url_for.

To work around this issue, you can pass location: nil for objects that don't have a URL:

respond_with(object, location: nil)

Or, if the URL can't be built automatically, you can help it by passing the right one:

respond_with(object, location: custom_url_for(object))
Reasons:
  • RegEx Blacklisted phrase (3): you can help
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Alexander S.