Skip to content
This repository

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

Open
lawitschka opened this Issue · 1 comment

2 participants

Moritz Lawitschka holacarol
Moritz Lawitschka
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 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.

Regards
Moritz

holacarol

+1

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.