Question

Inherited Resources seems to automatically set the status to 422 when a request fails validation and the response type is JSON. However, if the response type is html, the status is set to 200. Is there a way to tell inherited_resources to always return a 422 if the validation fails?

Cheers, Andy

No correct solution

OTHER TIPS

Here is a monkey patch that you can put in your initializers (tested on Rails 4.0.3):

class ActionController::Responder
  def navigation_behavior_with_errors(error)
    if !get? && has_errors? && default_action
      render :action => default_action, status: :unprocessable_entity
      return
    end

    navigation_behavior_without_errors(error)
  end

  alias_method_chain :navigation_behavior, :errors
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top