Since there was a lot of basic Ruby grammar in Chapter 4 of the Rails tutorial, I would like to output what I learned in Qiita together with Chapter 5.
In Chapter 4, there was a lot of talk about Ruby, so the impression that the code written in Chapter 4 was mainly about the contents of custom helpers. In Rails View, you can create new methods. This is what is called a custom helper. Other than the custom helper, it was about Ruby, so I will omit it here. I will summarize in Qiita how the basic grammar of Ruby will be useful for Rails development.
In Chapter 5, you will first learn how to use partial templates. You can insert it into your layout by using a Rails helper call called render. You can reduce the amount of CSS description by using Sass, but since I was doing Web production myself, the review is a pass.
Using what you created static_pages in Chapter 3, it's better to use/about instead of/static_pages/about. So, in Chapter 5, I learned how to write/about.
|Page name||URL||Named route|
It is necessary to modify routes.rb to realize the route URL as shown in the above table. Basically, write in _path format, and write in _url only in the case of redirect. Writing with a get rule allows you to call the about action of the StaticPages controller when a GET request is sent to/about. You can remove'static_pages/home' by using root_path or root_url.
Rails.application.routes.draw do root 'static_pages#home' get '/help', to: 'static_pages#help' get '/about', to: 'static_pages#about' get '/contact', to: 'static_pages#contact' get '/signup', to: 'users#new' end
Along with this, we will also modify the Static Pages controller. By defining the route, you can use the route (root_url, help_path, etc.) in the layout.
After modifying the route, test the link (integration test). The purpose of the test is to send a GET request to the root URL. Check if the correct page template is drawn. Check if the links to each page work properly.
After the integration test, implement user registration. The first thing to do when registering as a user is to generate a Users controller. Let new be the action for new user registration. To generate a Users controller, run the following command.
$ rails g controller Users new
If you can generate the controller file, this is the end of Chapter 5.
To be honest, I felt that I was studying as usual after the six consecutive holidays during the year-end and New Year holidays. I had a habit, and I didn't have to rush. I will study Chapter 6 from tomorrow, but I thought that I would just do it as usual.