我發現周圍的工作,我有我試圖排序基於upvotes遞減圖片:
我的解決方案:
在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
解決方案: 要麼冷凝查詢成一體,或由值每個查詢結果推入一個數組,然後排序。
編輯:這工作正常與MySQL的發展,但沒有那麼多PostgreSQL。我收到一個PG :: RESULT對象,我不太知道如何處理。
不可能在沒有提供任何日誌或類似的東西的情況下幫助您。請點擊此處閱讀如何調試Rails應用程序http://nofail.de/2013/10/debugging-rails-applications-in-development/ – phoet
它應該根據測試進行工作。我現在無法深入瞭解,但是生成的查詢是什麼? – NARKOZ
Rails Server在加載索引頁面時告訴我:Rendered /Users/USername/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/routing_error。救援內ERB /佈局 – piratebroadcast