josevalim/inherited_resources — Issue #187: Failure block not executed for API calls when using Rails 3.1
Author: lawitschka
Created: 2011-12-15 22:01:59+00:00
State: open

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

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

end
```

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: https://github.com/rails/rails/commit/48404a751d7cab1556c390a5915c90947d56b46e#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 using it 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.

Regards
Moritz