edgarjs / ajaxful-rating

Provides a simple way to add rating functionality to your application.

Home Page:http://rdoc.info/projects/edgarjs/ajaxful-rating

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rater_id not getting updated.

inasacu opened this issue · comments

Hi,

I have upgraded from gem version edgarjs-ajaxful_rating (2.1.3) to gem ajaxful_rating (2.2.8.2). I replaced user_id for the rater_id field. When updating as such:

INSERT INTO rates (rateable_type, created_at, rateable_id, rater_id, updated_at, stars, dimension) VALUES('Match', '2010-11-27 17:28:31', 4197, NULL, '2010-11-27 17:28:31', 4, 'technical')

The issue is that the rater_id is not getting populated. I inserted a new column in the table: user_id and the user_id field is getting populated by the rater_id is not.

I installed the plugin and worked with the code and was able to get this to work was by adding:

def rate(stars, user, dimension = nil)
  return false if (stars.to_i > self.class.max_stars)
  raise AlreadyRatedError if (!self.class.axr_config[:allow_update] && rated_by?(user, dimension))

  rate = if self.class.axr_config[:allow_update] && rated_by?(user, dimension)
    rate_by(user, dimension)
  else
    returning rates(dimension).build do |r|
      r.rater = user
    end
  end
  rate.rater_id = user.id  # code added by raul padilla
  rate.stars = stars
  rate.save!
  self.update_cached_average(dimension)
end

Can't tell you if I have something that may be causing this not to work as you intended but as I have done it seems to work for me. Is it possible to add this to the gem?

Hope it helps or you can help me. Thanks for your plugin.

Raul Padilla

It should set the rater id because it's doing the same that you added in this block:

returning rates(dimension).build do |r|
  r.rater = user
end