rake db:seed in rails

This is from the blog http://codedecoder.wordpress.com/ . Its about the rake in rails . rake db:seed

codedecoder

rake command is explained in this post . writing custom rake task is explained in this post.  db:seed is inbuilt rake task defined by rails. The rake db:seed command, basically execute whatever code you write in db/seeds.rb file of your application. Though can write any code in this file, by convention you should write code which populate your database with the basic data, for example: when ever your deploy your application somewhere, and create a new database for it, you want that user with admin credential must be present there. So you will write the code which create that user in this file. Below is the sample code which will create a user and assign admin role to him.

puts "********Seeding Data Start************" admin = User.create(:first_name => 'System', :last_name => 'Admin', :email => 'systemadmin@sunpower.com', :password => 'sunpoweradmin', :password_confirmation => 'sunpoweradmin', :source_system_id => 'systemadmin', :source_system => 'LP',:entity_type => "Customer", :target_system => "OPENAM")…

View original post 277 more words

Advertisements

About lokeshjain2008

hey i m here to help college going students. and i 'll
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s