Create Records
Create with new + save
user = User.new("John", "john@example.com")
if user.save
puts "Created user #{user.id}"
else
puts "Failed: #{user.errors.map(&.message).join(", ")}"
endCreate with save!
user = User.new("John", "john@example.com")
user.save! # Raises if validation fails
puts "Created user #{user.id}"Create in One Step
Create! in One Step
Create Multiple Records
Create with Relationships
Create with Default Values
Create with Timestamp
Handle Validation Errors
Verify Creation
Related
Last updated
Was this helpful?