-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