Today, I learned more about rails, here are some of the notes I took down:
When building any app it is important to do the following:
- Plan out your urls for the app that you are building
- Figure out what your database("db") needs to fulfill your task. Confirm if your db needs to change or what tables you need to create.
- If you end up creating/needing a new table, ask yourself: Do you need a model? Do you need to create or use the model generator?
- Then after all that, you should play with your database within your console.
When you first look at a rails application after learning Sinatra, you will see a lot of similar files. For example, you will still find a
config.ru file that your server will reference when you run
rails server in your terminal. Dont be nervous, running
rails server is the same as running
shotgun within a Sinatra app except rails runs on localhost:3000 and Sinatra runs on localhost:9393.
config.ru file will load the environment still and run your rails application. It should look something like this:
require_relative 'config/environment' run Rails.application
The Gemfile still holds all the dependencies.
The Rakefile, still loads all rake task for Rails.
And you still have models, controllers, and views. One major difference is routes. Routes are handled in a separate file and can be found in your config folder. An easy way to view the routes available to you on your rails application is to simply type
rails routes in your terminal.
When building a rails app, know that naming conventions are important, so keep the following in mind:
The table name should be lowercase with a pluralized name of the model.
The model file name should be singular lowercase and underscored
The class name for model should be singular camelcase.
Feel free to take a look at my practice rails application on Github.
Thank you for reading.
Song of the day: Roots Virtual Picnic
Top comments (0)