简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM