after_sign_in_path_for does not work
Hi everyone,
- Ruby v 2.6.3p32
- Rails v 6.0.2.1
- Devise v 4.7.1
I use three different Devise model with two domains. My routes.rb looks like this;
Rails.application.routes.draw do
constraints host: 'domain1.com' do
ActiveAdmin.routes(self)
devise_for :users, ActiveAdmin::Devise.config.merge(path: 'user')
devise_for :admin_users, ActiveAdmin::Devise.config.merge(path: 'admin')
root to: "users/dashboard#index", :as => :user
end
constraints host: 'domain2.com' do
resources :lists
devise_for :influencers
get '/lists' => 'lists#index', as: :influencer_root
root to: "lists#index", as: "All_List_Objects"
end
end
Also I added
def after_sign_in_path_for (resource)
stored_location_for(resource) ||
if resource.is_a?(Influencer)
return "/"
# return "/lists"
elsif resource.class == User
return "/"
else
root_path
end
end
to my Aplication_Controller.rb
Current behavior
I got these logs;
Redirected to http://localhost:3000/lists
Completed 302 Found in 126ms (ActiveRecord: 4.6ms | Allocations: 13282)
Expected behavior
I want to redirect to "/" after Influencers signed up with 200 code.
How can I solve it?
From looking at it, I'm imagining that there might be a stored location that it could be using. If that's not the case, can you please provide a sample app that shows the issue? If possible, without active admin involved.
From looking at it, I'm imagining that there might be a stored location that it could be using. If that's not the case, can you please provide a sample app that shows the issue? If possible, without active admin involved.
what is the recommended ways to override default devise method?
did putting the overrided code on application_controller.rb okay? or there is preferable way than that?
class ApplicationController < ActionController::Base
before_action :authenticate_user!
def after_sign_in_path_for(resource_or_scope)
signed_in_root_path(resource_or_scope)
end
end