responders
responders copied to clipboard
`redirect_to` cannot be called from `navigation_location` method
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
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!
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?
@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.