简体   繁体   中英

Different View for Devise sign_in/sign_out for 2 authentication model - User & Admin

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM