It's been a while since I first make my "Hello World" appear successfully on a website. Now, it's time to make more complicated stuff appear successfully as well.
Here are a few repeating steps that will ensure the first dynamic website (localhost) works:
- Generating models.
- Establish relationships between models.
- Setting up associations.
- Write the seed file.
- Create migration.
- Establishing routes.
- Run migration.
- Run seed file.
- Drafting methods under the model controller.
- Make view templates.
- Running the website on your server and start debugging!
Step 1: Generating models.
It is recommended to use rails terminal command line whenever you want to generate a new model. Commands such as "rails g resource ..." would make everything set up a lot faster than if you manually do it by using the graphic interface.
Step 2: Establish relationships between models.
This is the most important step. Make sure to understand the relationships between models and to get everything correctly. ActiveRecord is an amazing tool if you get all your relationships right. I draw all your models out into a paper so that I can visually imagine how my models will be related to each other. And I tend to look at them very often to see where things are going, like opening a map to make sure that "I'm not lost."
Step 3: Setting up associations.
After I've drawn all relationships into a paper, setting up associations should be easy. Most likely I'll have one-to-many, or many-to-many-through relationships. Has_many and belongs_to, make sure your pluralize and singular terms are corrected.
Step 4: Write the seed file.
Optional. Either write your own seed file or having the user to be able to create it themselves work!
Step 5: Create migration.
Migration... don't forget to migrate.
Step 6: Establishing routes.
If you're not too worried about Google eliminating your websites for having too many unused routes, using "resources" is fine. But as a good programmer you are, make sure to specify which route you're using so you don't have any unused routes.
Step 7: Run migration.
Run migrate...
Step 8: Run seed file.
Make sure your fake database is there.
Step 9: Drafting methods under the model controller.
Write your dynamic things here!
Step 11: Make view templates.
All pages that need a view should have a view. Using "_form.html.erb" would be so helpful! You might want to know a little more about html, since erb is the file with a combination of both ruby and HTML (and CSS as well).
Step 12: Running the website on your server and start debugging!
Learn more about debugging tools early on will help a lot!
Top comments (0)