2013-10-16 2 views
2

사용자 및 글꼴이있는 앱이 있습니다. 나는 ARRSystem을 설정하고 USers는 Like, Like 같은 것을 볼 수있다. 그러나 Likes에게 주문하려고 할 때활성 레코드 평판 시스템 레일 4 포크 find_with_reputation이 작동하지 않습니다.

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

작동하지 않습니다. 정렬이 발생하지 않습니다. 내 탐색 메뉴에 "Most Popular"및 "Most Recent"를 갖고 싶지만이 기능을 사용할 수는 없습니다. 나는이 정확한 gemfile 사용하고 있습니다 :

내 솔루션 : images_controller.rb에서

(인덱스 방법 나는 주위에 일을 발견 https://github.com/NARKOZ/activerecord-reputation-system/tree/rails4

+0

로그를 제공하지 않으면 도움을 줄 수 없습니다. 여기에 가서 레일 애플리케이션을 디버깅하는 방법을 읽어보십시오. http://nofail.de/2013/10/debugging-rails-applications-in-development/ – phoet

+0

테스트에 따라 작동해야합니다. 지금 당장은 파고 들지 않지만 검색어는 무엇인가요? – NARKOZ

+0

Rails 서버에서 색인 페이지를로드 할 때 다음과 같이 알려줍니다. 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에 따라 내림차순으로 정렬하는 것을 시도하고있다 이미지가)) 내 서버 로그를 찾고 있었어요 그리고 그것은 대신 (각 항목에 대해, 'find_with_reputation'쿼리를 내림차순으로, 하나 개의 쿼리로 모든 이미지를 당기는 모양 때문에 정렬 할 수 없습니다

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

. 그것은 또한 '가치'를 쿼리하지 않습니다.

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 

솔루션 : 하나에 쿼리를 응축, 또는 값을 기준으로 정렬 한 후 배열에 각 쿼리 결과를 밀어 어느.

편집 :이 문제는 PostgreSQL에서 MySQL로는 잘 작동하지만 PostgreSQL에서는 그렇지 않습니다. 내가 처리하는 방법을 잘 모르는 PG :: RESULT 객체를 받는다.

관련 문제