[Ruby on Rails] A memorandum of layout templates

This is the first draft. We would appreciate it if you could point out any deficiencies.

I'm studying Ruby on Rails. I wasn't sure why the content coded in the view file was displayed properly in the browser even though it was not enclosed in the DOCTYPE declaration or HTML tags, but I understood the layout template and it was refreshing, so I will leave it as a memorandum.

What is a layout template?

It is a file that is automatically created in the following directory when you create an application with rails. app/views/layouts/application.html.erb

Normally, from the action defined in the controller, if there is a view file, it seems that the file is called, but in reality, the view file created in the layout template is embedded and returned.

Example) When creating a controller called posts app/controllers/posts_controller.rb

posts_controller.rb


class PostsController < ApplicationController
  def index
  end
end

app/views/posts/index.html.erb

erb:index.html.erb


<h1>top page</h1>

Actually, what is returned as a response is the view file ** index.html.erb ** called in ** <% = yield%> ** in the tag of the template file below. It is said that it has been returned.

app/views/layouts/application.html.erb

erb:application.html.erb


<!DOCTYPE html>
<html>
  <head>
    <title>FirstApp</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>

index.html

Recommended Posts

[Ruby on Rails] A memorandum of layout templates
Ruby on Rails Basic Memorandum
Basic knowledge of Ruby on Rails
A note about the seed function of Ruby on Rails
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
[Ruby on Rails] Introduction of initial data
[Rails] Addition of Ruby On Rails comment function
[Ruby on Rails] Japanese notation of errors
Explanation of Ruby on rails for beginners ①
[Ruby on rails] Implementation of like function
Implementation of Ruby on Rails login function (Session)
[Ruby on Rails] Until the introduction of RSpec
Recommendation of Service class in Ruby on Rails
Ruby on Rails ~ Basics of MVC and Router ~
Ruby on Rails Elementary
Ruby on Rails basics
Rails new in Ruby on Rails ~ Memorandum until deployment 1
(Ruby on Rails6) Creating data in a table
Ruby On Rails Association
A series of flow of table creation → record creation, deletion → table deletion in Ruby on Rails
[Ruby on Rails] Individual display of error messages
I made a portfolio with Ruby On Rails
[Ruby on Rails] Implement a pie chart that specifies the percentage of colors
[Ruby on Rails] Asynchronous communication of posting function, ajax
[Introduction] Try to create a Ruby on Rails application
Build a Ruby on Rails development environment on AWS Cloud9
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
Explanation of Ruby on rails for beginners ② ~ Creating links ~
Try using the query attribute of Ruby on Rails
Explanation of Ruby on rails for beginners ⑦ ~ Flash implementation ~
Ruby on rails learning record -2020.10.03
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on rails learning record-2020.10.07 ②
Post a video on rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
[Ruby on Rails] Add a column with a foreign key constraint
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
[Ruby on Rails] Elimination of Fat Controller-First, logic to model-
(Ruby on Rails6) Display of the database that got the id of the database
Delete all the contents of the list page [Ruby on Rails]
[Ruby on Rails] Easy scroll animation of javascript (using ScrollReveal.js)
How to display a graph in Ruby on Rails (LazyHighChart)
Apply CSS to a specific View in Ruby on Rails
[Ruby on Rails] Carousel of bootstrap4 is implemented as a slide show using each method.
[Ruby on Rails] Read try (: [],: key)
Ruby on Rails variable, constant summary
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function
Progate Ruby on Rails5 Looking Back
[Rails Tutorial Chapter 5] Create a layout
How to use Ruby on Rails
Ruby on Rails Japanese-English support i18n
(Ruby on Rails6) "Erase" posted content
[Ruby on Rails] CSV output function