Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/axr/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ def axr_config(dimension = nil)
# # some page update here ...
# end
def rate(stars, user, dimension = nil)
return false if (stars.to_i > self.class.max_stars) || (stars.to_i < 1)
return false if (stars.to_i > self.class.max_stars(dimension)) || (stars.to_i < 1)
raise Errors::AlreadyRatedError if (!self.class.axr_config(dimension)[:allow_update] && rated_by?(user, dimension))

rate = if self.class.axr_config(dimension)[:allow_update] && rated_by?(user, dimension)
rate_by(user, dimension)
else
rates(dimension).build.tap do |r|
r.rater = user
r.dimension = dimension
end
end
rate.stars = stars
Expand Down Expand Up @@ -128,7 +129,10 @@ def raters(dimension = nil)

# Finds the rate made by the user if he/she has already voted.
def rate_by(user, dimension = nil)
rates(dimension).find_by_rater_id(user.id)
rates(dimension).
where(:dimension => dimension).
where(:rater_id => user.id).
first
end

# Return true if the user has rated the object, otherwise false
Expand Down