나는 사용자 리뷰 및 다른 사용자가 그들에 투표 기록 프로젝트에 Thumbs_up 보석을 사용하고 있습니다. 나는 같은 문제에 부딪쳤고 아래의 해결책을 생각해 내었다. 그것은 우아하지 않지만 작동합니다. 경험이 많은 사람이 더 나은 솔루션을 제공 할 수 있기를 바랍니다. 내 사용자 모델에서
내가 가진 :
class Review < ActiveRecord::Base
attr_accessible :heading, :body, :notes, :published, :user_id, :vote_cnt
acts_as_voteable
belongs_to :user
###############################################################################
# update the vote_cnt field in the database, for sorting and query purposes.
def update_vote_count
if self.vote_count != self.vote_cnt
self.vote_cnt = self.vote_count
self.save
end
end
end
를 내 리뷰 컨트롤러 I에서 : 나는 투표를 캐스팅 될 때마다 업데이트 vote_cnt 속성 및 DB 열 :
class User < ActiveRecord::Base
acts_as_voter
has_karma(:chapters, :as => :user) # tracks "up votes" for all a user's chapters
has_many :reviews
end
내 리뷰 모델은있다 내 리뷰보기에 투표 링크에 클릭을 처리 할 작업이 있습니다
################################################################
def vote_for
@review = Review.find(params[:id])
begin # try-rescue
current_user.vote_for(@review)
@review.update_vote_count
redirect_to review_path(@review), :notice => "Successfully voted for this review."
rescue
redirect_to review_path(@chapter), :notice => "Sorry, can't vote for a review twice, or you don't have voting rights."
end
end
를 이제 알 후 드디어 리뷰 '당첨에 의해 주문 CURRENT_USER 액세스 리뷰의 집합을 검색 할 수 있습니다 L :
@reviews [email protected]_by(current_ability).order("vote_cnt DESC")
내가 우아하지 말했듯이,하지만 작동합니다. 당신은 나의 리뷰를 구조화 했으므로 마이크로 포스트를 구조화 할 수 있습니다. 희망이 당신을 도와줍니다.
정말 도움을 주시면 고맙겠습니다. 내일 다시 시도해 드리겠습니다. 어떻게 진행되는지 알려 드리겠습니다. 다시 한 번 감사드립니다! – Kellogs