In my app I have a table for ROLES. Pretty simple:
1: Admin, DESC stuff
2: Guest, Desc stuff
etc..
The issue I just got hit with was I went to deploy the app on heroku and everything broke, reason was that these default roles in the database were not populated on deployment… Something I hadn’t thought about.
With Rails 3, is there a way to say, hello Mr Rails, here are the table’s default values? on migrate or database create?
Thanks
There is a concept called Seed Data in Rails which you can use to do this.
There is a file called seeds.rb is created in the db directory. In which you can create such things.
So for example
will go into this file.
You can call
rake db:seedto seed this data into your application.There is a railscast about this as well – http://railscasts.com/episodes/179-seed-data.