Title: Devise gem, rails 3, adding first record to db
Tags: ruby-on-rails;devise;cancan
Question: This may be my most stupid question yet:
I've implemented this tutorial on my Rails 3 app to get Devise up and running with CanCan. What is the right way to enter the first record in your development database, when only admins are allowed to enter a record and a null record isn't allowed? Do you just hack away some of the code to reduce permissions, then put it back again?
Update: to add to the answer, if you put this in seeds.db it works, even though there's no password field in the User table:
User.create(:email => 'galvannancy@example.net',:password => 'secret')

Here is the accepted answer: Use db/seeds.rb to write the code for your admin record. And call rake db:seed to execute that. Make sure you check whether the initial records are already created, so that running rake db:seed won't duplicate the data.
Comment for this answer: optionally you can put it in a migration...that guarantees that you don't have to worry about duplicating the user. Some people bridle at putting this sort of thing in the migration, of course...


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:07/13/11', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ruby-on-rails><devise><cancan>', 'Title': 'Devise gem, rails 3, adding first record to db', 'ViewCount': 160, 'id': 6683692, 'user_AboutMe': '<p>Publisher-turned-coder. One of the developers of consonance.app.</p>\n', 'user_AccountId': 372532.0, 'user_DisplayName': 'snowangel', 'user_Reputation': 3392.0, 'user_Views': 821.0, 'user_id': 721631.0}}