سؤال

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?

هل كانت مفيدة؟

المحلول

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

User.with_role(:coach)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top