Different View for Devise sign_in/sign_out for 2 a

2019-09-14 14:05发布

问题:

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.

回答1:

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



回答2:

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