Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_render has a breaking change in Rails 5 #126

Closed
davetron5000 opened this issue Jun 28, 2015 · 4 comments
Closed

default_render has a breaking change in Rails 5 #126

davetron5000 opened this issue Jun 28, 2015 · 4 comments

Comments

@davetron5000
Copy link

See rails/rails#20276

Opening this issue to get some guidance on how to use the fix in Rails 5 to fix this gem.

Basically, this: https://github.com/plataformatec/responders/blob/master/lib/action_controller/responder.rb#L236 will no longer raise ActionView::MissingTemplate, which is what much logic is assuming will happen.

I believe the fix should be something like:

def default_render
  if @default_response
    @default_response.call(options)
  else
    controller.default_render(options) do
      raise ActionView::MissingTemplate  # <--------
    end
  end
end

but I have very little familiarity with this gem (I discovered this issue because devise uses this gem and my devise-based flow stopped working on Rails master).

So, I'm happy to do the work of trying to address this, but wondering if someone more familiar with the codebase can let me know if this is the right general approach.

@ppworks
Copy link
Contributor

ppworks commented Jul 17, 2015

Thanks!

ActionView::MissingTemplate.new raise wrong number of arguments (0 for 5+) error.

So, I pass some dummy options like following.

module My
  class AppResponder < ActionController::Responder
    include Responders::FlashResponder
    include Responders::HttpCacheResponder

    # @see https://github.com/plataformatec/responders/issues/126
    def default_render
      if @default_response
        @default_response.call(options)
      else
        controller.default_render(options) do
          raise ActionView::MissingTemplate.new([], "", [], true, []) # <--------
        end
      end
    end
  end
end

@ppworks ppworks mentioned this issue Jul 17, 2015
@nashby
Copy link
Collaborator

nashby commented Jul 24, 2015

Closing this since #131 was merged. @davetron5000 thanks for reporting it! Can you please give master branch a try?

@ppworks thanks for the patch!

@nashby nashby closed this as completed Jul 24, 2015
@davetron5000
Copy link
Author

This solves the problem I was seeing. Thanks!!!

@jachenry
Copy link

I'm still having issues using respond_with on rails 5 using ActionController::API as the base controller. Below is the controller I'm testing against:

class V1::UsersController < ApplicationController
  # GET /users/me
  # GET /users/:id
  def show
    if current_user.nil?
      respond_with status: not_found
    else
      respond_with current_user
    end
  end
end

The respond_with call eventually makes it to the controller.render(options) but the options parameter is always empty. The last stop is the render(*args, &block) method below which eventually spits out an empty string (" ").

actionpack/lib/abstract_controller/rendering.rb

# Normalizes arguments, options and then delegates render_to_body and
# sticks the result in <tt>self.response_body</tt>.
# :api: public
def render(*args, &block)
  options = _normalize_render(*args, &block)
  self.response_body = render_to_body(options)
  _process_format(rendered_format, options) if rendered_format
  self.response_body
end

Edit

This may all be caused because Active Model Serializers no longer support respond_with according to this bug in AMS repo. I understand their argument but it would have been nice to satisfy devise serialization without the need to override every devise method.

Edit

The empty string that does get returned (" ") is not valid json. I'm going to revert back to the older version until this is fixed for devise/active model serializer

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

No branches or pull requests

4 participants