簡體   English   中英

rails(devise / cancan / rolify):更有效的方式來獲得具有特定角色的用戶

[英]rails (devise/ cancan /rolify): more efficient way to get users 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>
          <% }%>

這個簡單的任務看起來代碼太多了。 有一個更好的方法嗎?

它就在自述文件https://github.com/EppO/rolify上

User.with_role(:coach)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM