I want to include meta tags in my homepage view. But I do not want to include it in the head section of the application.html.erb
file directly, as this will cause it to include the meta tags on all pages which is redundant for my app.
View templates HTML tags provide static web pages only but ERB tags give us dynamic information in that HTML template. To view the template file, go to Rails application >> app >> View>> Home folder where the templates files are available.
csrf_meta_tags are indications for ajax requests to use these as one of the form parameters to make a request to the server. Rails expects the csrf as part of your form body (params) to process your requests. Using these meta tags you can construct the form body or the csrf header to suit your needs.
<meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings. Metadata will not be displayed on the page, but is machine parsable.
You can put
<% if content_for?(:head) %>
<%= yield(:head) %>
<% end %>
in head
section of application.html.erb
layout.
Then, in view in which you want to include these tags:
<% content_for :head do %>
<!-- your tags -->
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With