My models:
class House
belongs_to: country
scope :published, -> { where(published: true) }
end
class Country
has_many: houses
end
I want to show the houses which are published and from country x;
house_controller:
@country = Country.friendly.find(params[:country_id])
@houses = @country.houses.published.order(:sorting)
I get the error "undefined method `published"
What am i doing wrong?
House.published
?@country
isnil
, I bet you'd be getting "undefined method 'published' for NilClass" or something like that, which would make total sense. Is@country
nil?ActiveRecord::Base
Please post it properly