Update syntax on ruby [closed]
How do I update in ruby?
My database is: Books
width: Id, Title and Date
To create I would do:
@book = Book.create
@book.id = 1
@book.Title = "HP: Last One"
@book.Date = "2011-01-01"
@book.save
Now, if I want to update the Book with Id = 1, what to do?
If you use Active Record (for example through Rails), provided that you have model Book
that derives from ActiveRecord::Base
and that book
is an instance of it (for example: book = Book.find(1)
will find you a book with id of 1), it would be something like: book.update_attributes(:title=>"new title", :date=>new_date)
; or book.title = "new title"; book.date = new_date; book.save
.
No idea about other object-relational mappings, though.
精彩评论