Search code examples
ruby-on-railsrubydevisecancanrolify

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?


Solution

  • It's right on the readme https://github.com/EppO/rolify

    User.with_role(:coach)