I have a Company object with an associated Location.
Company has_many :locations Location belongs_to :company
When I call:
@company = Company.find(5).includes(:locations)
I get the error:
NoMethodError: undefined method `includes' for #<Company:0x000000066ad398>
I'm following the rubyonrails.org instructions to a T... as far as I can tell.
find() triggers a database query, and returns an instance of the model. You can't call includes on it, as includes is supposed to have an ActiveRecord::Relation as receiver.
You need to invert the order: find must stay at the end:
@company = Company.includes(:locations).find(5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With