I did a find on some model and got the following
>> @addy
=> [#<Address id: 3, street: "Some Street", houseNumber: nil, created_at: "2010-01-20 06:09:52", updated_at: "2010-01-20 06:09:52", address_id: 16>]
Now how do I retrieve the values? what if i want the street?
@addy.street does not work netiher does @addy[:street]
what if i had a list of @addy’s and wanted to loop through them to show street for each?
@addy.first.streetshould work, as it is list of Adress classes containing only one member.For displaying each street for more adresses in list:
or
Edit:
When you have problem identifying what class you have, always check
object.class. When you just useobjectin IRB, then you see output fromobject.inspect, which doesn’t have to show class name or even can spoof some informations. You can also callobject.methods,object.public_methods.And remember that in Ruby some class is also an instance (of Class class). You can call
@addr.methodsto get instance methods and@addr.class.methodsto get class methods.Edit2:
In Rails
#findcan take as first parameter symbol, and if you pass:firstof:last, then you’ll get only one object. Same if you pass one integer (id of retrieved object). In other cases you get list as result, even if it contains only one object.