如何在用户登录时更改根路径? (我使用设计)
在应用程序控制器中我有:
def after_sign_in_path_for(resource)
'/dashboard' || user_dashboard_path
end
在route.rb中我尝试过:
Rails.application.routes.draw do
root to: "subscribers#new"
authenticated :user do
get '/dashboard', to: 'dashboard#index', as: :dashboard
root to: "dashboard#index", as: :user_dashboard
end
但是,正在发生的事情是,在注册后它会重新导向/仪表板,这很棒,但是如果我点击链接到根路径的主链接,它会回到订阅者#new,当它应该转到仪表板#index,因为用户已登录。
我做错了什么?
谢谢!
答案 0 :(得分:2)
在路线文件中尝试这样的事情:
authenticated :user do
root to: "home#index"
end
unauthenticated :user do
root "home#visitor"
end
文档:http://www.rubydoc.info/github/plataformatec/devise/ActionDispatch/Routing/Mapper:authenticated