Im trying to figure out how i would get attributes/propertys from an object.
locations.rb model would have attribute :city
@location = Location.where(:id => 1)
Seems to go find inside my controller but how would I get access to the :city from that @location ?
I tried all combinations and thought it had to be:
- @location.city
- puts @location.city needs to print value of city
But instead I’m getting
undefined method `city' for #<ActiveRecord::Relation:0x007ff2d1506330>
Anyone could clarify why this not work and what I miss here? Ive searched for examples on how to do this and tried all combinations to no avail 🙁
thx
Arel’s
wherequery returns a collection of models, even if there is only one result.Location.where(:id => 1)will effectively return an array (actually anActiveRecord::Relation) ofLocationobjects, even though there will only be one result from this particular query in that array.To get around this, either do