Guest User

Untitled

a guest
May 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. ## method in my User model -this works but would like to refactor to more elegant block if possible
  2.  
  3. def self.find_next_user_by_role(role)
  4. @last_set_user_id = Client.last.user_id || 0
  5. @users = Role.find_by_name(role).users
  6. user_id = @users.first.id
  7. @users.each_with_index do |user,index|
  8. if user.id == @last_set_user_id
  9. if @users[index] == @users.last
  10. user_id = @users.first.id
  11. else
  12. user_id = @users[index+1].id
  13. end
  14. end
  15. end
  16. return user_id
  17. end
Add Comment
Please, Sign In to add comment