Failure block not executed for API calls when using Rails 3.1 #187

lawitschka opened this Issue Dec 15, 2011 · 2 comments

3 participants

class UsersController < InheritedResources::Base
  respond_to :json
  actions :create, :show

  def create
    create! do |success, failure|
      failure.any { render :text => "Error", :status => 200 }


In this minimal (and not that useful) example, the failure block on create will never be executed. There has already been a ticket to this, but it has been closed by the author because he could not reproduce the error.

I stumbled upon this error while writing a little API and I wanted custom error responses. After some time of debugging I found the issue's source in ActionController::Responder#to_format, which changed significantly from 3.0 to 3.1.

The "faulty" commit which caused IR to be broken is this one: rails/rails@48404a7#actionpack/lib/action_controller/metal/responder.rb

The default_renderer now only gets called if the request was a GET request and the resource does not have any errors which is definitely not the (from an IR point of view) expected behavior.

The question arising here is how to deal with this issue. I'm not that into the Rails Core that I could propose any kind of solution/workaround. I'm not even sure there is any. Maybe I'm even using the feature wrong....

If there is no solution, it would be best to either delete the functionality from IR or explicitly say that this feature does not work with Rails 3.1.




Same problem. It even doesn't work with the create! do |format|. Anything inside format.json (for example) is not executed.


Rails 3.1 is not supported anymore. If you can reproduce this issue in a modern Rails version please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment