Last Updated: February 25, 2016
· noahsark769

Don't let seed data fail silently in rails

When developing with rails, use the create! function rather than the create function in your seeds.rb file. Since model creation should never fail when you're seeding the database, using create! will throw an error when the model cannot be saved to the database, whereas create will fail silently and maybe produce mind bending bugs.

Do this:

User.create!(:username => 'user1', :password => 'password')

Not this:

User.create(:username => 'user1', :password => 'password')

3 Responses
Add your response

Your "Do this" and "Not this" are identical. Probably should drop the ! from the second one.

over 1 year ago ·

User.create!( username: 'user1', password: 'password')

over 1 year ago ·

Thanks markjreed, you're correct!

over 1 year ago ·