How to copy or clone model?

Posted by Zeck on Stack Overflow See other posts from Stack Overflow or by Zeck
Published on 2010-06-14T10:23:18Z Indexed on 2010/06/14 10:32 UTC
Read the original article Hit count: 234

Filed under:
|
|

I have a model Book with attributes id, name, price. I have an instance of Book:

b1 = Book.new
b1.name = "Blah"
b1.price = 12.5
b1.save

I would like to copy b1, create another instance of the Product model. I'm tryid p1=b1.clone then p1.save but it didn't work. Any idea?

And my environment is:

  • Netbeans 6.9 RC2
  • JRuby 1.5.0

Thanks

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby