【发布时间】:2014-01-31 04:21:55
【问题描述】:
我正在使用 Rails 4,我想对给定帖子的每个单独的帖子评论进行投票计数。
架构:
Post PostReview PostReviewVote
id post_id post_review_id
user_id user_id
voted_on_date
我有类似的东西:
table.table.table-striped.table-hover
thead
tr
th Post Name
th Reviews Created For Post
th Total Votes in All Reviews For Post
tbody
- for post in @posts
tr
td= post.name
td= PostReview.where(post_id: post.id).size
td= PostReview.where(post_id: post.id).PostReviewVotes.size
但它没有获取,引用运行时错误:
undefined method `PostReviewVotes' for #<ActiveRecord::Relation []>
有什么建议吗?我的模型有正确的关联,仅供参考。
【问题讨论】:
-
你说他们有适当的关联。
Post是否有关联:has_many :PostReviewVotes, through: PostReview?
标签: ruby-on-rails ruby activerecord ruby-on-rails-4 where