Rails: How to include meta tags in views and not in application.html.erb?

pratski picture pratski · Jun 26, 2013 · Viewed 13k times · Source

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.

Answer

Marek Lipka picture Marek Lipka · Jun 26, 2013

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 %>