简体   繁体   English

用于2种身份验证模型的设备sign_in / sign_out的不同视图-用户和管理员

[英]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 我已经制作了具有2种不同身份验证模型的简单测试应用-用户-管理员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. 请随时修改我的github存储库以具有不同的sign_in / sign_up视图。 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 在应用程序控制程序中,我添加了一个名为after_sign_in_path_for的方法,该方法检查角色并重定向到所需的视图,这里是一个方法

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: 基本上,Deep在这里提供了答案:

github.com/plataformatec/devise#configuring-views github.com/plataformatec/devise#configuring-views

do this: 做这个:

rails generate devise:views users Rails产生devise:views用户

set: 组:

config.scoped_views = true inside the config/initializers/devise.rb file. 在config / initializers / devise.rb文件中,config.scoped_views = true。

updating the git repo to reflect this feature. 更新git repo以反映此功能。 thanks @Deep 谢谢@Deep

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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