0
我需要使用百分比的votes_count。通过使用counter_cache轨道进行百分比计数4
我的关系是
celebrity.rb
has_many :votes
vote.rb
belongs_to :celebrity, counter_cache: true
我控制器
def show_celebrity
@celebrity = Celebrity.includes(:category).where('category_id = ?', params[:id])
@celebrity.each do |celeb|
celeb["votes_count"] = celeb.votes.count
end
respond_to do |format|
format.json { render json: @celebrity }
end
end
我怎样才能使百分比的votes_count?票数/总数票* 100