Quote Rails Tutorial
First move to the working directory
cd ~
Command execution after moving
$ rails generate controller <Controller name> <Action name> <Action name>・ ・ ・
#Example
$ rails generate controller StaticPages home help
If you execute the above command
・ Creating a controller -Routing settings -Creating a view file It is very convenient and easy because it automatically creates!
In fact, you can make a page with just this.
For example, when you want to create a new about page, you can add it by manually creating a file or writing code.
① Routing settings ② Add action to the controller ③ Create view file
config/routes.rb
Rails.application.routes.draw do
get 'static_pages/home'
get 'static_pages/help'
get 'static_pages/about'← Add
end
app/controllers/static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
end
def help
end
def about ← added
end ← added
end
③ Create view file Right-click on about.html.erb in app/views/static_pages to create a new one
ruby:app/views/static_pages/about.html.erb
<h1>Create About</h1>
・ ・ ・
・ ・ ・
・ ・ ・
This completes the page addition.
The URL can be opened on the web by adding static_pages/about at the end. (https://~~~/static_pages/about)
Recommended Posts