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

redirect_to cannot be called from navigation_location method #222

Open
benebrice opened this issue Jul 20, 2020 · 3 comments
Open

redirect_to cannot be called from navigation_location method #222

benebrice opened this issue Jul 20, 2020 · 3 comments

Comments

@benebrice
Copy link

I'm implementing an Engine with web render. Main Application is api_only
redirect_to method is delegated to the controller class (delegate :head, :render, :redirect_to, to: :controller) but seems to be private (even if source says another way). Here is an example where it breaks.

# application_controller
class ApplicationController < ActionController::API

end

# my_engine/users/sessions_controller
module MyEngine
  class Users::SessionsController < Devise::SessionsController
    include ActionController::Redirecting
    include ActionView::Layouts
    include ActionController::Flash

    respond_to :html
  end 
end

Error is

NoMethodError in MyEngine::Users::SessionsController#create

private method `redirect_to' called for #85 MyEngine::Users::SessionsController:0x00007fed79550140> Did you mean? redirect_back

I was able to fix it by redefining redirect_to on a public method which will be use in navigation_location method

# my_engine/users/sessions_controller
module MyEngine
  class Users::SessionsController < Devise::SessionsController
    include ActionController::Redirecting
    include ActionView::Layouts
    include ActionController::Flash

    respond_to :html

    def redirect_to(options = {}, response_options = {})
      super
    end
  end 
end
@phawk
Copy link

phawk commented Feb 5, 2021

I'm having this issue as well, fresh install of devise 4.7.3 on a newly generated Rails 6.1.1 app.

Placing your override redirect_to method into ApplicationController fixed for me, thank you!

@rafaelfranca
Copy link
Collaborator

Maybe there is something in the app making redirect_to private? The method is public in the framework and in the responders gem. Can you try to check the method(:redirect_to).source_location inside that controller?

@4lllex
Copy link

4lllex commented Apr 27, 2022

@rafaelfranca it is calling ActionController::Flash#redirect_to. We've debugged the issue here, with a few solutions and reproducible code: https://stackoverflow.com/a/71988972/207090

I think this is more of a configuration issue. Try not to use Flash inside API controller. Or could be a bug, not sure who's.

When using ActionController::Base, redirect_to method calls Instrumentation#redirect_to first. But when including ActionController::Flash in an api controller, it is included after Instrumentation and sometimes it doesn't like that.

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