分别validation用户和管理员

class ApplicationController  ["welcome#index"] # before_filter :authenticate_user! :except => ["welocme#index"] def after_sign_in_path_for(user) # user_dashboard_index_path user_dashboard_index_path end def after_sign_out_path_for(user) welcome_index_path end after_filter :authenticate_admin! def after_sign_in_path_for(admin) admin_dashboard_index_path end def after_sign_out_path_for(admin) welcome_index_path end end 

管理员不应访问用户仪表板,同样用户不应访问管理仪表板。

我怎样才能做到这一点?

我在我的项目中完成了:

  protect_from_forgery with: :exception def after_sign_in_path_for(resource) if user_signed_in? user_dashboard_index_path elsif admin_signed_in? admin_dashboard_index_path else xyz_path end end 

注销相同:

 def after_sign_out_path_for(resource) if user_signed_in? welcome_index_path elsif admin_signed_in? welcome_index_path else xyz_path end end 

用于身份validation

在(欢迎/索引)

 <% if user_signed_in? %> contant_of user <% else %> you are not authenticated #admin can not authenticate this page <% end %> 

希望它会有所帮助