Merge pull request #2211 from TracksApp/prefer-find-by-over-detect

Prefer find_by over detect
This commit is contained in:
Matt Rogers 2019-05-06 08:43:51 -05:00 committed by GitHub
commit 19168f262d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,7 +28,7 @@ class User < ApplicationRecord
end
def update_positions(project_ids)
project_ids.each_with_index {|id, position|
project = self.detect { |p| p.id == id.to_i }
project = self.find_by(id: id.to_i)
raise I18n.t('models.user.error_project_not_associated', :project => id, :user => @user.id) if project.nil?
project.update_attribute(:position, position + 1)
}