a method called "adding_user_record" is annoying me. 5 lines of code replaced with 2

This commit is contained in:
Sam 2013-04-05 17:53:39 +11:00
parent ea8d69fbd6
commit 5273657537
1 changed files with 2 additions and 6 deletions

View File

@ -287,18 +287,14 @@ class User < ActiveRecord::Base
user_visits.where(visited_at: date).first user_visits.where(visited_at: date).first
end end
def adding_visit_record(date)
user_visits.create!(visited_at: date)
end
def update_visit_record!(date) def update_visit_record!(date)
unless seen_before? unless seen_before?
adding_visit_record(date) user_visits.create!(visited_at: date)
update_column(:days_visited, 1) update_column(:days_visited, 1)
end end
unless seen?(date) || has_visit_record?(date) unless seen?(date) || has_visit_record?(date)
adding_visit_record(date) user_visits.create!(visited_at: date)
User.update_all('days_visited = days_visited + 1', id: self.id) User.update_all('days_visited = days_visited + 1', id: self.id)
end end
end end