Friday, May 18, 2012

Re: [Rails] Help with find

Person.where.limit returns a collection, you can to use .first, .last, .each. etc to access the element(s) or you can to use Person.find(34) in this case.


2012/5/18 brent brent <lists@ruby-forum.com>
Folks
 When im in rails 3.2 console i can do this just fine

 p = Person.last
 p.last_name

 and it prints the last name.

 But when i try to find it by the id, its able to locate the single
record and store it in my variable p, but i cant print the last_name
column. For example.


  p = Person.where(id: 34).limit(1)

  "printing p here shows all the columns"

  p.last_name says this

NoMethodError: undefined method `last_name' for
#<ActiveRecord::Relation:0x000000055f8840>

any help would be appreciated, thanks.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--
Fernando Almeida
www.fernandoalmeida.net

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate