You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
When you set up axr without dimensions in Rails 3.1 and vote, dimension=&... is always passed in url and because of that @model.rate(stars, current_user, "") is called instead of @model.rate(stars, current_user, nil). This affects somehow a cached rating which does not get updated after the first call. This is what happens in my rails console:
ruby-1.9.3-p125 :019 > p.rate(1, User.find(1))
User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Rate Load (1.7ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 7 AND "rates"."rateable_type" = 'Part' AND "rates"."dimension" IS NULL AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (1.8ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 7 AND "rates"."rateable_type" = 'Part' AND "rates"."dimension" IS NULL AND "rates"."rater_id" = 1 LIMIT 1
(0.8ms) BEGIN
(57.0ms) UPDATE "rates" SET "stars" = 1, "updated_at" = '2012-03-17 05:54:35.885397' WHERE "rates"."id" = 6
(9.6ms) COMMIT
(1.9ms) SELECT SUM("rates"."stars") AS sum_id FROM "rates" WHERE "rates"."rateable_id" = 7 AND "rates"."rateable_type" = 'Part' AND "rates"."dimension" IS NULL
(1.5ms) SELECT COUNT(*) FROM "rates" WHERE "rates"."rateable_id" = 7 AND "rates"."rateable_type" = 'Part' AND "rates"."dimension" IS NULL
(0.8ms) BEGIN
(1.8ms) UPDATE "parts" SET "average_rating" = 2.5, "updated_at" = '2012-03-17 05:54:35.969188' WHERE "parts"."id" = 7
(4.2ms) COMMIT
=> true
ruby-1.9.3-p125 :020 > p.rate(2, User.find(1), "")
User Load (1.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Rate Load (1.7ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 7 AND "rates"."rateable_type" = 'Part' AND "rates"."dimension" IS NULL AND "rates"."rater_id" = 1 LIMIT 1
Rate Load (1.4ms) SELECT "rates".* FROM "rates" WHERE "rates"."rateable_id" = 7 AND "rates"."rateable_type" = 'Part' AND "rates"."dimension" IS NULL AND "rates"."rater_id" = 1 LIMIT 1
(0.9ms) BEGIN
(1.4ms) UPDATE "rates" SET "stars" = 2, "updated_at" = '2012-03-17 05:57:32.882623' WHERE "rates"."id" = 6
(54.7ms) COMMIT
=> nil
The issue can be easily fixed by making your controller method looking like:
When you set up axr without dimensions in Rails 3.1 and vote,
dimension=&...
is always passed in url and because of that@model.rate(stars, current_user, "")
is called instead of@model.rate(stars, current_user, nil)
. This affects somehow a cached rating which does not get updated after the first call. This is what happens in my rails console:The issue can be easily fixed by making your controller method looking like:
or even simplier
but maybe it would be better to solve it in axr itself.
The text was updated successfully, but these errors were encountered: