Introduction

Rails is a full-stack web application framework running on the Ruby programming language. It ships with all the tools needed to build amazing web apps on both the front and back end.

Rails does everything from rendering HTML templates, updating databases, sending and receiving emails, maintaining live pages via WebSockets, enqueuing jobs for asynchronous work, storing uploads in the cloud, providing solid security protections for common attacks and a lot more.

It is designed to make programming web applications easier by making assumptions about what every developer needs to get started.

<aside> 💡 Rails is opinionated software. It makes the assumption that there is a "best" way to do things, and it's designed to encourage that way - and in some cases to discourage alternatives.

</aside>

The Rails philosophy includes two major guiding principles:

Rails comes with a number of scripts called generators that are designed to make your development life easier by creating everything that's necessary to start working on a particular task.

Understanding the folder structure of a Rails Project

The new application generator will provide you with the foundation of a fresh Rails application so that you don't have to write it yourself.

For a beginner the scaffolded/generated project will be overwhelming so lets understand the folder structure in breif.

File/Folder Purpose
app/ Contains the controllers, models, views, helpers, mailers, channels, jobs, and assets for your application.
bin/ Contains the rails script that starts your app and can contain other scripts you use to set up, update, deploy, or run your application.
config/ Contains configuration for your application's routes, database, and more.
config.ru Rack configuration for Rack-based servers used to start the application.
db/ Contains your current database schema, as well as the database migrations.
GemfileGemfile.lock These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem.
lib/ Extended modules for your application.
log/ Application log files.
public/ Contains static files and compiled assets. When your app is running, this directory will be exposed as-is.
Rakefile This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.
README.md This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.
storage/ Active Storage files for Disk Service.
test/ Unit tests, fixtures, and other test apparatus.
tmp/ Temporary files (like cache and pid files).
vendor/ A place for all third-party code. In a typical Rails application this includes vendored gems.
.gitattributes This file defines metadata for specific paths in a git repository. This metadata can be used by git and other tools to enhance their behavior.
.gitignore This file tells git which files (or patterns) it should ignore.
.ruby-version This file contains the default Ruby version.

The default web server distributed by rails is Puma.

therubyrhino is the recommended runtime for JRuby users and is added by default to the Gemfile in apps generated under JRuby.

MVC Architecture

MVC is a design pattern that divides the responsibilities of an application to make it easier to reason about. Rails follows this design pattern by convention.

A route maps a request to a controller action. A controller action performs the necessary work to handle the request, and prepares any data for the view. A view displays data in a desired format.