Ok, I\'m probably going to feel quite dumb when someone answers this one with a simple thing that I\'m missing but... here goes:
I\'ve got a brand new app on rails 3
There is convenient way for populating tables - db/seed.rb file. Just add the script for creating users in it and run:
rake db:seed
Below you can see example of User
model with email
and username
fields:
# Inserting default security users
users = {
admin: {
username: 'admin',
email: 'admin@gmail.com',
password: 'adminpass',
password_confirmation: 'adminpass',
is_admin: true
},
administrator: {
username: 'administrator',
email: 'administrator@gmail.com',
password: 'administrator',
password_confirmation: 'administrator',
is_admin: true
}
}
users.each do |user, data|
user = User.new(data)
unless User.where(email: user.email).exists?
user.save!
end
end
Note, that devise validations are applied here.
Here you can find more examples of using the seed.rb
file and here is the rayn's rails cast.