create_records
🚀 Create Records with new
and create
​
Active Record provides two main ways to create records: new
+ save
and create
. Use new
when you want to build an object, run custom logic, then save it. Use create
for one-step creation.
# Using new + save
todo = Todo.new(title: 'Buy milk', done: false)
todo.save
# Using create (builds and saves in one go)
post = Post.create(title: 'Hello World', content: 'My first post')