问题描述
我有两种类型的用户,并为他们生成了设计模型和视图。基本上必须这样做是因为在这里毫无疑问使用角色。两个用户都是不同的,并且将具有不同的仪表板。还必须将数据存储在不同的表中,因为这些数据将在上进一步处理。我已经成功地为他们两个创建了不同的路线,但是现在我打算继续前进,我想遵循一个确定的结构,以后不会出现问题。我采用了多态的方式来关联模型,并将它们命名为用户A和用户B。
I have 2 types of users , and generated devise models and views for them . Had to do this basically because using roles was out of question here . Both Users are different and will have different dashboards . Also have to store there data in different tables as those will be further processed on . I was successful in creating different routes for both of them but now as i plan to move forward , i want to follow a definite structure which won't cause problems later . I went the polymorphic way to associate the models and also namespaced them as User A and User B.
用户A
将能够发布查询
将能够为B释放付款
将能够保留和删除工作
用户B
将在完成工作时收到付款
Will receive payments on completing job
将能够查看工作
*注-这些只是我必须完成的许多功能的一部分。
*Note - These are just some of the functions of the many i have to accomplish .
我看过SO的其他问题,但我没有得到具体的答案。期待那些可能取得相同或相似情况的人的建议。预先感谢。
I have looked into other questions at SO but i didn't get a concrete answer . Looking forward to suggestions from those who might have achieved the same or have been in a similar situation . Thanks in advance .
推荐答案
首先使用CanCanCan获得许可
Firstly use CanCanCan for permission
add角色列进入数据库,并生成能力模型
add role column into your database, and generate ability model
将角色定义为用户模型
enum role: [:Admin, :Enduser, :Moderator]
用于不同的仪表板
制作仪表板控制器
class DashboardController < ApplicationController
def index
end
end
根仪表板
root 'dashboard#index'
in views / dashboard / index.html.erb
in views/dashboard/index.html.erb
<% if current_user.role == "Admin" %>
<%= render 'admin' %>
<% elsif current_user.role == "Moderator" %>
<%= render 'moderator' %>
<% elsif current_user.role == "ClientUser" %>
<%= render 'client_user' %>
<% end %>
在views / dashboard / index.html.erb中使文件
in views/dashboard/index.html.erb make file like
_admin.html.erb
_moderator.html.erb
_client_user.html.erb
,然后根据您的要求将不同的视图插入到不同的文件中。
and insert different views into different file as per your requirement.
这篇关于具有不同仪表板的多个Devise用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!