[RUBY] Try to summarize the common layout with rails

This time I would like to share how to write a common layout in a rails html file in one file. I think there is a file called application.html.erb under viwes / layout. You can avoid writing the same code by putting together the common layout parts in that file as shown below.

<!DOCTYPE html>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

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

  <div class="header-logo">
    <%= link_to("TweetApp","/") %>
  <ul class="header-menus">
    <%= link_to("What is TweetApp","/about") %>
  <%= link_to("Post list","/posts/index") %>
    <%= yield %>

The content of the above

  • tag was originally from another html file. It is useful to know that there is also a way to combine them into one like this time.

    Recommended Posts

    Try to summarize the common layout with rails
    Addicted to the webpacker that comes standard with Rails 6
    Try using view_component with rails
    [With back tricks] How to introduce React to the simplest Rails
    Let's summarize how to extend the expiration date of Rails
    Try to imitate marshmallows with MiniMagick
    Connect to Rails server with iPhone
    How to get along with Rails
    Introducing React to Rails with react-rails
    Try to imitate the idea of a two-dimensional array with a one-dimensional array
    Super beginner builds Rails6 + Postgresql environment with Docker to the end
    [Rails] How to introduce kaminari with Slim and change the design
    I tried to summarize the methods used
    How to decorate the radio button of rails6 form_with (helper) with CSS
    [Rails] How to use rails console with docker
    Deploy to heroku with Docker (Rails 6, MySQL)
    [Rails] How to use the map method
    Prepare the format environment with "Rails" (VScode)
    Change the layout when rotating with onConfigurationChanged
    Try deploying Rails app to EC2-Part 2 (Deploy)-
    [Rails] How to get the user information currently logged in with devise
    Check the processing contents with [rails] binding.pry
    I tried to summarize the Stream API
    How to compare only the time with Rails (from what time to what time, something like)
    Try changing the .erb file to .slim
    How to display the text entered in text_area in Rails with line breaks
    The process of introducing Vuetify to Rails
    I want to introduce the committee with Rails without getting too dirty
    [Rails] How to apply the CSS used in the main app with Administrate
    How to build Rails 6 environment with Docker
    [Rails] How to read the XML file uploaded from the screen with Hash type
    [Rails6] How to connect the posting function generated by Scaffold with the user function generated by devise
    [Rails] How to register multiple records in the intermediate table with many-to-many association
    Android development-WEB access (POST) Try to communicate with the outside and send data. ~
    [Rails] How to operate the helper method used in the main application with Administrate
    [Rails] When transitioning to a page with link_to, move to the specified location on the page
    [Rails] How to decide the destination by "rails routes"
    Print forms directly to the printer with JasperReports
    [Rails] Button to return to the top of the page
    Downgrade an existing app created with rails 5.2.4 to 5.1.6
    The road to Japaneseizing Rails devise error messages
    Android app: Try to summarize events and listeners
    [Rails] rails new to create a database with PostgreSQL
    [Rails] I tried to raise the Rails version from 5.0 to 5.2
    Assignment to multiple variables with the ternary operator
    I tried to organize the session in Rails
    Try to link Ruby and Java with Dapr
    Publish the app made with ruby on rails
    Rails Tutorial Chapter 1 From Zero to Deployment [Try]
    [Swift] How to link the app with Firebase
    Try to implement login function with Spring Boot
    The code I used to connect Rails 3 to PostgreSQL 10
    Try deploying Rails application to EC2-Part 2 (Server construction)-
    Deploy Rails to ECS Fargate with AWS Copilot
    One way to redirect_to with parameters in rails
    I want to play with Firestore from Rails
    Try to get redmine API key with ruby
    Implement the Like feature in Ajax with Rails.
    [Rails] How to easily implement numbers with pull-down
    How to build API with GraphQL and Rails
    Try to implement TCP / IP + NIO with JAVA