Active Record Reputation System Rails 4 fork find_with_reputation无效

时间:2013-10-16 19:06:10

标签: ruby-on-rails ruby-on-rails-4

我有一个包含用户和字体的应用。我设置了ARRSystem和USers可以喜欢,就像可以在Font show页面上看到的那样。但是,当我尝试用喜欢的方式订购它们时

def index
    @fonts = Font.find_with_reputation(:likes, :all, {:order => 'likes desc'})
end

它不起作用。没有排序。我想在我的导航菜单中有“最受欢迎”和“最新”,但无法使其正常工作。我正在使用这个确切的gemfile:https://github.com/NARKOZ/activerecord-reputation-system/tree/rails4

1 个答案:

答案 0 :(得分:1)

我找到了一个工作,我有一些图像,我试图根据upvotes对desc进行排序:

我的解决方案:

在images_controller.rb(索引方法)

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) }

我正在查看我的服务器日志,它看起来像是用一个查询拉下所有图像,降序,每个项目的'find_with_reputation'查询(因此无法排序)。它也不会查询'价值'。

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

解决方案: 将Query压缩为一个,或将每个查询结果推送到一个数组中,然后按值排序。

编辑:这在使用MySQL的开发中运行良好,但在PostgreSQL中没有那么多。我收到一个PG :: RESULT对象,我不太清楚如何处理。

相关问题