Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## method in my User model -this works but would like to refactor to more elegant block if possible
- def self.find_next_user_by_role(role)
- @last_set_user_id = Client.last.user_id || 0
- @users = Role.find_by_name(role).users
- user_id = @users.first.id
- @users.each_with_index do |user,index|
- if user.id == @last_set_user_id
- if @users[index] == @users.last
- user_id = @users.first.id
- else
- user_id = @users[index+1].id
- end
- end
- end
- return user_id
- end
Add Comment
Please, Sign In to add comment