How can I redirect a user's home (root) path based on their role using Devise?

后端 未结 5 2062
天涯浪人
天涯浪人 2020-12-02 11:18

I\'m working on a project management app, and in the app, I have project_managers and clients. I\'m using Devise and CanCan for authenticat

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 11:58

    The simplest solution is to use lambda:

    root :to => 'project_managers#index', :constraints => lambda { |request| request.env['warden'].user.role == 'project_manager' }
    root :to => 'clients#index'
    

提交回复
热议问题