[RUBY] How to make an almost static page with rails

Quote Rails Tutorial

Command execution in terminal

First move to the working directory

cd ~

Command execution after moving

$ rails generate controller <Controller name> <Action name> <Action name>・ ・ ・

$ 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.

When you want to add a new page

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

① Routing settings


Rails.application.routes.draw do
  get  'static_pages/home'
  get  'static_pages/help'
  get  'static_pages/about'← Add

② Add action to the controller


class StaticPagesController < ApplicationController

  def home

  def help

def about ← added
end ← added

③ Create view file Right-click on about.html.erb in app/views/static_pages to create a new one


<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

How to make an almost static page with rails
[Rails] How to build an environment with Docker
[Rails] How to make seed
How to get along with Rails
How to specify db when creating an app with rails
How to make an app using Tensorflow with Android Studio
How to crop an image with libGDX
[Rails] How to use rails console with docker
Let's make an error screen with Rails
How to build Rails 6 environment with Docker
How to make an app with a plugin mechanism [C # and Java]
Downgrade an existing app created with rails 5.2.4 to 5.1.6
Rails6.0 ~ How to create an eco-friendly development environment
[Rails] How to easily implement numbers with pull-down
How to build API with GraphQL and Rails
How to make a follow function in Rails
How to make an crazy Android music player
How to write Rails
How to uninstall Rails
How to make shaded-jar
Rails6 I want to make an array of values with a check box
How to make an image partially transparent in Processing
How to make a factory with a model with polymorphic association
[Rails] How to search by multiple values ​​with LIKE
How to make LINE messaging function made with Ruby
How to make an oleore generator using swagger codegen
How to delete a new_record object built with Rails
How to make JavaScript work on a specific page
How to manually generate a JWT with Rails Knock
How to output standard from an array with forEach
[How to insert a video in haml with Rails]
[Rails] How to deal with URL changes after render
How to make Laravel faster with Docker for Mac
How to query Array in jsonb with Rails + postgres
How to get started with creating a Rails app
[Docker + Rails] How to deal with Rails server startup failure
[Rails] How to display an image in the view
How to create an application
Java --How to make JTable
[Rails] How to use enum
How to read rails routes
How to use rails join
How to number (number) with html.erb
How to update with activerecord-import
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
How to handle an instance
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
How to automatically generate ER diagram when migrating with Rails6
I tried to make an introduction to PHP + MySQL with Docker
How to set environment variables when using Payjp with Rails
Let's write how to make API with SpringBoot + Docker from 0