- Discuss the domain (with others or yourself).
- Write down the user stories (features that you plan to support).
- Develop an understand of how each noun (model/table) will relate to each other.
- Draw the schema. Don't name any join tables as the combination of two other tables, find a unique noun.
- Double check your schema for any columns that don't follow convention (e.g. foreign keys should end in
_id). - Ensure you've chosen the most appropriate type (integer, string, boolean, etc) for each column.
- Create the migrations for each table.
- Check that everything that matches your schema design.
- Migrate (note, you don't need any models defined to migrate!)
- Create the ActiveRecord models.
- Verify your models are in good shape by saving an instance of each to the database. (via
rake console).
- Add one or two associations to your models at a time. Don't do them all at once.
- As you add each association, update your
seeds.rbto make use of the association. Be sure to use the bang versions (create!andsave!) so any errors are printed when you runrake db:seed. Considerseeds.rbyour scratch pad as you develop & test your associations. - Review your
seeds.rband make sure you aren't manually setting any_idattributes. Set the association instead (presidentinstead ofpresident_id). Also, don't "guess" any values for an foreign key. If you need a randomUser, pick a random one withUser.all.sample. - Jump back and forth between dropping, migrating, seeding and the console to verify everything. Keep a checklist so you can be sure you've tested & verified each association is working like you expect.
- By now your
seeds.rbmight be a bit messy since you used it as a scratch pad. Reviewseeds.rband make sure you've got a decent set of data to test you application once you start creating the web interface. Now might be a good time to review your user stories/features.
Now it's time to create the routes & views for your app. Start with the easiest to the most difficult. Be sure to follow the RESTful routing conventions. Nearly every URL should include the plural form of the model (/comments/...).
Routes & views that display data (index & show) are going to be very helpful for testing that your app is working, so be sure you get those working first -- and working well.
Repeat the following for each model you plan on exposing CRUD functionality for (only create the routes & view for the CRUD actions you need!):
- Create a new controller file (
app/controllers/plural_model_name.rb) - Create a view folder (
app/views/plural_model_name) - Create the
indexroute & view - Create the
showroute & view - Create the
newroute & view + thecreateroute - Create the
editroute & view + theupdateroute - Create the
deleteroute.