0
快速导轨部分,例如我有两个模型用户和角色,我想创建一个基于某个角色的用户索引/列表,我该如何去构建在我的控制器rails 3使用where子句从两个模型创建索引
是它像
#first create the association
@user = role.build
#then build the index based on a Role of role_id = 2
@userrole = @user.where(@user.role_id == 2)
我知道这是伪代码,但是这是正确的?什么是适当的导轨代码?
这是我如何得到它的工作@users = User.includes(:角色)。凡( 'roles.id'=> 2) – jmorrissette