I have a simple question regarding Ruby on Rails, ActionView, Application.html.erb and the use of HTML head tags.
I know that application.html.erb is used for displaying content across all pages on your site.
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="My desciprtion.">
<meta name="robots" content="index,follow">
<title><%= @title %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true, :cache => "cache/all" %>
<%= javascript_include_tag "application", :async => true, "data-turbolinks-track" => true, :cache => "cache/all" %>
<%= csrf_meta_tags %>
</head>
That means, the above code is displayed on all of my web pages.
Now, I've been reading about SEO and it suggests using seperate description meta tags for every web page, to tell search engines what a page is about. My question to you is
Are you allowed to customize individual pages in rails like
page1.html.erb
page2.html.erb
page3.html.erb
and include the HTML head tag inside them?
I've been working with Ruby on Rails for quite some time, but I have never seen a head tag inside a view page.
I haven't seen a body tag to for that matter.
I have used
<% @title = "Page Title" %>
to declare individual titles for pages. That would be the equivalent of HTML Title tag.
Is there something similar for declaring a description for every web page?
You could alter your header to:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= yield :meta %>
<meta name="robots" content="index,follow">
<title><%= yield :title %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true, :cache => "cache/all" %>
<%= javascript_include_tag "application", :async => true, "data-turbolinks-track" => true, :cache => "cache/all" %>
<%= csrf_meta_tags %>
</head>
Then in your views you can do:
<% content_for :meta do %>
<meta name="description" content="blah">
<% end %>
<% content_for :title, 'My title' %>