[Rails] How to add new pages

Steps to increase Ruby on Rails pages

It is a memo for myself so as not to forget it.

procedure

    1. Describe the URL and the corresponding action in the route file of config
  1. Added the action corresponding to controller
    1. Create a new html.erb file in the view folder

Describe the URL and action in the route file

~ How to write ~

HTTP protocol "URL to display page" => "Controller name #Action name" It is described as.

A concrete example is shown below.

route.rb


get "images/index" => "images#index"

When receiving a request to the URL ~ / images / index In this program, it is written to execute the index action in the images controller.

Added the action corresponding to controller

images_controller.rb


def index
end

As I wrote in the route file earlier, after receiving the URL request The program comes to see the images controller. It then looks for the index action and tries to execute it. This time, we are working to increase the flow itself by one, so we will add the corresponding action.

Create a new html.rb in the view folder

The html.rb file is finally displayed on the browser. route→controller→html

html:index.html.rb


<h1>sample</h1>

Recommended Posts

[Rails] How to add new pages
How to write Rails
How to uninstall Rails
How to add / remove Ruby on Rails columns
How to conditionally add html.erb class in Rails
[rails] How to post images
How to add ActionText function
[Rails] How to use enum
[Rails] How to install devise
How to use rails join
[Rails] Add column to devise
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
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
How to add HDD to Ubuntu
[Rails] How to use Scope
How to add Hyperledger Iroha Peer
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
Rails new fails to install mysql
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[rails] How to display db information
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Rails] How to speed up docker-compose
Rails on Tiles (how to write)
[Rails] How to write exception handling?
[Rails] How to install ImageMagick (RMajick)
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
[Rails] Add strong parameters to devise
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails
How to add the delete function
[Introduction to Rails] How to use render
How to install Swiper in Rails
[Xcode] How to add a README.md file
How to add local jar to maven pom.xml
How to implement search functionality in Rails
Migration file to add comment to Rails table
How to change app name in rails
How to use custom helpers in rails
[Ruby on Rails] How to use CarrierWave
[Rails] How to upload images using Carrierwave
How to insert a video in Rails
[Java] How to add data to List (add, addAll)
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)