[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: ActiveRecord: method find Segmentation fault

David Heinemeier Hansson

12/21/2004 10:19:00 AM

> c=Customer.new(\"name\"=>\"liubin\",\"password\"=>\"passwd\")
> c.save
> puts \"new id is \"+c.id.to_s
> cs=Customer.find(2)
> cs.each{|c| puts \"user #{c.name} has password #{c.password}\"}

If you want Customer to return an array, you need to ask it with one,
like:

customers = Customer.find([2])
customers.each { |c| puts "user #{c.name} has password #{c.password}" }

You also don't want to escape the quotes as you did in the example.

I don't know why Ruby crumbles and dies on it, though. Seems a bit
excessive ;)
--
David Heinemeier Hansson,
http://www.basec... -- Web-based Project Management
http://www.rubyon... -- Web-application framework for Ruby
http://macro... -- TextMate: Code and markup editor (OS X)
http://www.loudthi... -- Broadcasting Brain