开发者

Update syntax on ruby [closed]

It's difficult to tell what is being asked here. This question is am开发者_运维百科biguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜