Lesson Weekend

Rails is more robust than Sinatra and adheres to strict RESTful routing patterns for our CRUD processes. Rails also employs the Ruby philosophy of "convention over configuration". Much of the behind-the-scenes "magic" that happens is the result of automation based on naming standards and common practices. This means that naming is really important for things to work properly in Rails.

MVC Pattern in Rails

Rails follows what's called a model-view-controller (MVC) pattern. In this pattern, we use models (our classes), views (our pages) and controllers (our routing hub between external requests and internal processes and output) to manage the request-response cycle. Below is an image that illustrates how a request is routed and a response is returned with Ruby on Rails.

Rails Process Graphic

When the browser makes a request to the web server, a route parses the request and passes it to the controller, which calls the model to do some work. The controller takes the result of that work, finds the view and finally, returns HTML output back to the browser.

When we build apps in Rails, the way we build the database and ActiveRecord models will not change from how we built them in Sinatra. The difference will be how routes and controllers handle incoming requests, and how data is managed and displayed in the response.

Here is the same graphic representation of the process showing the names and sample code that we'd create with a simple to do app using Ruby on Rails:

Rails Process Graphic with Files

We will go through this process as we rebuild our record store application to use Rails!

Lesson 2 of 34
Last updated July 14, 2022