Rails in one lesson

Contents
Models views controllers
Routes
ActiveRecord sketch
How a Rails app starts

Models views controllers

Rails splits every feature into three roles with fixed homes. Models hold data and rules, views render pages, and controllers connect the two.

The sketch below shows where one todo feature lives inside a fresh application.

# app models todo file holds the model # app views todos folder holds the pages # app controllers todos file holds the actions

Routes

Routes map URLs to controller actions in one central file. One resources line creates the full set of list, show, create, update, and delete paths.

Read the routes file as the table of contents for the whole application.

Rails.application.routes.draw do resources :todos root "todos#index" end

ActiveRecord sketch

ActiveRecord models look like plain Ruby classes with database powers mixed in. The sketch below runs without any database at all.

Learn the shape first with plain attributes, then let Rails add persistence, validations, and relations later.

class Todo attr_accessor :title, :done def initialize(title) @title = title @done = false end end

How a Rails app starts

A new Rails application starts from two typed commands. Install the rails gem once, then generate a fresh project folder.

Nothing below boots an application. Treat this lesson as a map, then build the two capstones with plain Ruby first.

gem install rails

rails new blog

Next: Capstone: todo CLI

Article author: Arthur Isaev

Related articles
Ruby
Ruby course: zero to hero in 50 lessons
What is Ruby and where it runs
Install Ruby and check the version
irb: the interactive shell
Your first Ruby script
Variables
Numbers
Strings
Symbols
Truthiness: only false and nil
Conditions
Loops
Arrays
Hashes
Ranges
Methods
Blocks, procs, lambdas
String tools
Files and IO
Exceptions
Modules and mixins
Classes and objects
Inheritance
Enumerables
Duck typing and core idioms
Gems and Bundler
Testing with Minitest
Debugging
Encodings
Time and date
JSON and YAML
HTTP clients
Sockets
REST APIs
puts, print and p
Metaprogramming
Enumerators
Pattern matching
Arguments: splats and kwargs
Rake tasks
Environment and CLI
Logging
CSV
ERB templates
WEBrick server
Rails in one lesson
Capstone: todo CLI
Capstone: JSON API
Performance
Modern Ruby tour
Hero roadmap: the whole course on one page
Install Ruby on Windows 11
Install Ruby on Ubuntu
Install Ruby on Rocky Linux
Install Ruby on macOS
Install Ruby on FreeBSD
Ruby in Docker
Threads and fibers

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: