-
Notifications
You must be signed in to change notification settings - Fork 123
Find_with_reputation in Rails 4 #62
Comments
same here. |
When trying to use this method, my specs print the following error: DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. I get this when calling something like: |
I found a work around, I have images which I am trying to sort desc based upon upvotes: My Solution: In images_controller.rb (index method) image_ids = ActiveRecord::Base.connection.execute("SELECT target_id FROM rs_reputations WHERE target_type = 'Image' ORDER BY value DESC")
image_ids = image_ids.map { |item| item = item[0] }
@images = []
image_ids.each { |id| @images << Image.find(id) } I was looking at my server logs and it looks like the instead of pulling all images with one query, descending, 'find_with_reputation' queries for each item (and therefore cannot sort). It also doesnt query 'value'. ReputationSystem::Reputation Load (0.2ms) SELECT "rs_reputations".* FROM "rs_reputations" WHERE "rs_reputations"."reputation_name" = 'votes' AND "rs_reputations"."target_id" = 14 AND "rs_reputations"."target_type" = 'Image' LIMIT 1
ReputationSystem::Reputation Load (0.3ms) SELECT "rs_reputations".* FROM "rs_reputations" WHERE "rs_reputations"."reputation_name" = 'votes' AND "rs_reputations"."target_id" = 15 AND "rs_reputations"."target_type" = 'Image' LIMIT 1
ReputationSystem::Reputation Load (0.3ms) SELECT "rs_reputations".* FROM "rs_reputations" WHERE "rs_reputations"."reputation_name" = 'votes' AND "rs_reputations"."target_id" = 17 AND "rs_reputations"."target_type" = 'Image' LIMIT 1 Solution: |
@rjswenson's solution worked for me. Note that to paginate the results with |
See http://stackoverflow.com/q/22617224 for a possible fix. In short, use:
|
FYI, I have a fork with a Rails 4 branch... all tests are passing and I'm using it on a Rails4 + Ruby 2 application without problems... you can try that and let me know if things are not working there: https://github.com/caiosba/activerecord-reputation-system/tree/rails4 |
try with
|
Hi,
Does this method work with Rails 4 yet?
This is my gem file:
gem 'activerecord-reputation-system', github: 'NARKOZ/activerecord-reputation-system', branch: 'rails4'
When I try this in my controller nothing gets ordered:
find_with_reputation(:votes, :all, :order => "votes desc")
Thanks
The text was updated successfully, but these errors were encountered: