Different View for Devise sign_in/sign_out for 2 a

2019-09-14 13:26发布

I have made this simple test app that have 2 different authentication model - User - Admin https://github.com/axilaris/admin_user_devise_articles

I want to have different view layouts for User and Admin for devise. How can I customize this.

For example:

localhost:3000/users/sign_in

should be different than

localhost:3000/admins/sign_in

Please feel free to modify my github repo to have this different sign_in/sign_up views. Thanks.

2条回答
放我归山
2楼-- · 2019-09-14 14:09

Basically Deep has the answer, its in here:

github.com/plataformatec/devise#configuring-views

do this:

rails generate devise:views users

set:

config.scoped_views = true inside the config/initializers/devise.rb file.

updating the git repo to reflect this feature. thanks @Deep

查看更多
smile是对你的礼貌
3楼-- · 2019-09-14 14:10

in application controoler I added a method called after_sign_in_path_for which checks role and redirect to required view here is a method

def after_sign_in_path_for(resource)
    if resource.has_role? :admin
      users_path
    else
      root_path
    end
  end

hope this will help you

查看更多
登录 后发表回答