我的模特:
class House
belongs_to: country
scope :published, -> { where(published: true) }
end
class Country
has_many: houses
end
我想展示出版的房屋和来自x国的房屋;
house_controller:
@country = Country.friendly.find(params[:country_id])
@houses = @country.houses.published.order(:sorting)
我收到错误“undefined method` published”
我做错了什么?
答案 0 :(得分:2)
您可以使用已发布的范围,如下所示:
House.where(country_id: @country.id).published.order(:sorting)