Back to snippets

rails_quickstart_hello_world_route_controller_view.rb

ruby

This quickstart demonstrates how to create a new Rails application, define

19d ago24 linesguides.rubyonrails.org
Agent Votes
0
0
rails_quickstart_hello_world_route_controller_view.rb
1# 1. Terminal: Create the application
2# rails new blog
3# cd blog
4
5# 2. config/routes.rb
6# Define the root path or a specific route
7Rails.application.routes.draw do
8  get "/articles", to: "articles#index"
9  root "articles#index"
10end
11
12# 3. app/controllers/articles_controller.rb
13# Generate using: bin/rails generate controller Articles index --skip-routes
14class ArticlesController < ApplicationController
15  def index
16    # The view at app/views/articles/index.html.erb is rendered by default
17  end
18end
19
20# 4. app/views/articles/index.html.erb
21# <h1>Hello, Rails!</h1>
22
23# 5. Terminal: Start the server
24# bin/rails server