[英]rails (devise/ cancan /rolify): more efficient way to get users with certain role
This is my code to get all user with certain role 这是我的代码,以使所有用户具有某些角色
<% users = User.all%>
<% users.each{ |user|%>
<% if not user.has_role? 'coach'%>
<% next%>
<% end%>
<option value="<%=user.id%>"><%=user.first_name%> </option>
<% }%>
It looks too much code for this simple task. 这个简单的任务看起来代码太多了。 Is there a better way to do this?
有一个更好的方法吗?
它就在自述文件https://github.com/EppO/rolify上
User.with_role(:coach)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.