-1
我的模型:范围的关系不工作
class House
belongs_to: country
scope :published, -> { where(published: true) }
end
class Country
has_many: houses
end
我想表明这是出版,从国十条的房屋;
house_controller:
@country = Country.friendly.find(params[:country_id])
@houses = @country.houses.published.order(:sorting)
我得到的错误 “未定义的方法`出版的”
我到底做错了什么?
在控制台上,就可以成功地做到'House.published'? – 2014-09-02 14:37:12
如果'@ country'是'nil',我敢打赌你会得到'未定义的方法'发布为'NilClass'或类似的东西,这将是完全意义上的。 '@ country'是否为? – 2014-09-02 14:38:18
你的模型看起来不好看不到'ActiveRecord :: Base'请正确发帖 – 2014-09-02 14:42:26