Ruby on Rails Tutorial

Build your first Rails application with this step-by-step guide covering setup, models, and API integration.

🚀 Get Started

1. Installation

Mac/Homebrew

brew install ruby
gem install rails
rails -v
                    

Ubuntu

sudo apt update
sudo apt install ruby-full
gem install rails
                    

2. Create New App

rails new blog_app
cd blog_app
rails server
                

Preview at localhost:3000

3. Generate Model

rails generate model Post title:string body:text published:boolean
rails db:migrate
            

4. Create Controller

Posts Controller

rails generate controller Posts index show
                    

Add Routes

resources :posts, only: %i[index show]
                    

5. Create Views

index.html.erb

%{ for post in @posts }
  h2= post.title
  p= post.body
%{ end }
                    

show.html.erb

h= @post.title
p= @post.body