【发布时间】:2017-02-28 20:17:43
【问题描述】:
我试图在产品展示页面中显示评分最高的评论,但它显示的是 # 而不是评论。任何想法为什么?
#comment model
class Comment < ApplicationRecord
belongs_to :user
belongs_to :product
scope :rating_desc, -> { order(rating: :desc) }
scope :rating_asc, -> { order(rating: :asc) }
end
#product model
class Product < ApplicationRecord
has_many :orders
has_many :comments
def highest_rating_comment
comments.rating_desc.first
end
end
#product show page
<%= @product.highest_rating_comment %>
【问题讨论】:
标签: ruby-on-rails ruby rails-models