2013-10-16 43 views
2

我有一個用戶和字體的應用程序。我設置了ARRSystem和USers可以像,可以在字體顯示頁面上看到。但是,當我嘗試通過喜歡與他們訂購Active Record Reputation System Rails 4 fork find_with_reputation不工作

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

它不起作用。沒有排序發生。我想在我的導航菜單中選擇「最流行」和「最新」,但無法實現此功能。我使用這個確切的Gemfile:https://github.com/NARKOZ/activerecord-reputation-system/tree/rails4

+0

不可能在沒有提供任何日誌或類似的東西的情況下幫助您。請點擊此處閱讀如何調試Rails應用程序http://nofail.de/2013/10/debugging-rails-applications-in-development/ – phoet

+0

它應該根據測試進行工作。我現在無法深入瞭解,但是生成的查詢是什麼? – NARKOZ

+0

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

回答

1

我發現周圍的工作,我有我試圖排序基於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對象,我不太知道如何處理。