Rails: DAY 6

iOS
3 min readMay 22, 2019

This week I decided to take a deeper dive into Rails and wanted to write about my experience. Over the next few articles I will explain the following:

  1. What is Rails, basic explanation and overview?
  2. Models — Active record, migrations, validation, callbacks
  3. Views — Layouts and Rendering, Form helpers
  4. Controllers — Action controller
  5. Rails — Rails Routing form the Outside In
  6. Digging Deeper — Active support cord, Mailer, Active Job, Active Storage, Testing Rails Applications, debugging, configuring Rails, command line, asset pipeline, rails initialization process, caching, active support
  7. Extending Rails — Rails on Rack, Rails generators & Templates, engines, threading and code execution

What is Rails?

It is a open source web application framework built with the Ruby language. Rails is a collection of code, tools and utils that give developers a specific structure to work with. Rails will help Ruby / web developers build websites faster by taking an opinionated development approach, conventions should be more important than configuration.

How does Rails work?

Rails receive a request and routes the request to the appropriate controller#action, which then interacts with the database (via Active Record) to fulfill the request. Rails uses the MVC architecture and controllers make decisions on how to process the request & they ask the database for any data that it needs. Then the controller renders the view.

How to create a new Rails project?

I found the documentation to be very helpful, I followed the instructions step by step from

Explain the auto-generated files from creating a project?

What is the purpose of the controller?

In Rails controllers are called Action Controllers, the purpose of a controller is to receive specific requests from the application. After the router has determined which controller to use for a request, the controller is responsible for making sense of the request, and producing the appropriate output. The controller is a middle man between the model and views, it makes the model data available to the view so it can display data to the user.

What are the controller naming conventions?

The naming convention of controller in Rails favors pluralization of the last word in the controller’s name. For example ClientsController is preferable to ClientController.

How do you create a controller?

rails generate controller Welcome index — creates a controller, view and route for the the action Welcome and index.

Why does every controller inherit from ApplicationController?

Action Controllers are the core of a web request. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action. An action is defined as a public method on the controller, which will automatically be mode accessible to the web-server through Rails Routes.

Only the ApplicationController inherits from ActionController::Base. All other controllers inherit from ApplicationController. This gives the developer the ability to configure things such as a request forgery protection and filtering of sensitive request parameters.

I have explained what Rails is, how it works, how to create a new project, talked about controllers and their purpose as well as why all controllers inherit from ApplicationController. In the next article I will explain Models, Views and how to retrieve and display data to the user.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

iOS
iOS

Written by iOS

iOS Developer, Go, Java, C#, Blockchain enthusiast, Data junkie

No responses yet

Write a response