[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
Let's summarize "MVC" of Ruby on Rails
part of the syntax of ruby ​​on rails
[Ruby on Rails] Japanese notation of errors
Explanation of Ruby on rails for beginners ①
[Ruby on rails] Implementation of like function
[Ruby on Rails] Until the introduction of RSpec
Recommendation of Service class in Ruby on Rails
Rails new in Ruby on Rails ~ Memorandum until deployment 2
Introducing Rspec, a Ruby on Rails test framework
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
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
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 <2021> Implementation of simple login function (form_with)
[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
Implementation of Ruby on Rails login function (devise edition)
Docker the development environment of Ruby on Rails project
[Ruby on Rails] Implementation of tagging function/tag filtering function
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 ~
Portfolio creation Ruby on Rails
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 basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
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
Ruby on Rails for beginners! !! Summary of new posting functions
[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.