Ruby on Rails: Nikita - NikitaDouglas/acebook-Kindred GitHub Wiki

This is an overview of what I have learnt about Ruby on Rails this week.

Our group took some time on Wednesday and Thursday to do some self-led learning time, before launching into creating our Facebook clone. I used this time to work through the Codeacademy Learn Ruby on Rails course. I'm documenting my learnings here.

Getting started with Rails

Rails is a server-side web application framework written in the Ruby language - it is a big step up from Sinatra, the web framework that we have used thus far to build web applications. You can start a new rails project with the following command:

''' rails new '''

This will generate a lot of folders and files that form the basis of a Rails application. My teammate Sophie did a great diagram about the file structure in our Rails application.

The MVC pattern seems to be the foundation of how Rails works - you can generate Models and Controllers with the rails generate model/controller <name> command, which will again create several folders and files that form the basis of these components. Rails is super-strict about where things go and how things are done, and it's worth working with these rules rather than against them.

Rails Request/Response Cycle

I took. screengrab of a really useful diagram from the Codecademy course that details how the model, controller, and view interact with each other, and how this feeds back to the client:

The Request/Response Cycle in Ruby on Rails

As you can see the config/routes.rb folder is central to how a Rails application works - it directs the user depending on their URL request to the pages they need to see, which are backed up by a controller and a model.

Rails Controller

The controller in Rails has seven actions which map on to the different HTTP requests that can be made. Here's a table of those 7 actions:

Rails Controller Actions

A controller can be generated with the rails generate controller <controller name> command - the controller's name is usually plural, whilst the model is a singular i.e. users_controller.rb and user.rb. This command will create the _controller.rb file in app/controllers.

⚠️ **GitHub.com Fallback** ⚠️