Reputation: 266910
I want to create a new object, passing it some initial values, and then saving to the db and return the saved object.
how can I do this?
example:
What's the ruby way of doing this?
Upvotes: 5
Views: 4900
Reputation: 107718
user = User.create(:user_age => 35)
This will initialize a new object, set the user_age
attribute to 35, save it to the database and return the User
object which represents that record in the database.
Upvotes: 6