Reputation: 5619
I want to prefill my table with the seeds.rb file in app/db
but there I got a problem during storing the right data.
in the table users I have an column called active withe datatype tinyint. so now I want to store with the seeds.rb int values
User.create([ { :id => 1, :firstname => 'Felix', :lastname => 'Hohlwegler', :active => 1}])
but it dosn't store 1. It always stores 0 in database.
also tried this:
User.create([ { :id => 1, :firstname => 'Felix', :lastname => 'Hohlwegler', :active => true}])
same problem it stores 0 in db.
Whats going wrong?
Upvotes: 0
Views: 200
Reputation: 5619
solution that works fine for me:
u = User.new(
:id => 1, :firstname => 'Felix', :lastname => 'Hohlwegler', :active => 1
)
u.active = true
u.save
Upvotes: 0
Reputation: 106882
The most common thing that causes this kind of problems are validations. In this case I would expect that a user needs an email or a password. Please check if
User.create!(
:id => 1, :firstname => 'Felix', :lastname => 'Hohlwegler', :active => true
)
passes the validations and creates an user.
Please note that I use create!
that would raise an error if it not able to create an user instead of just returning an unsaved one.
Upvotes: 1