简体   繁体   English

Rails:如何在视图中而不是application.html.erb中包括元标记?

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

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. 但是我不想直接将它包含在application.html.erb文件的头部,因为这将导致它在所有页面上包含meta标签,这对我的应用程序来说是多余的。

You can put 你可以放

<% if content_for?(:head) %>
  <%= yield(:head) %>
<% end %>

in head section of application.html.erb layout. application.html.erb布局的head部分。

Then, in view in which you want to include these tags: 然后,在要包含这些标签的视图中:

<% content_for :head do %>
  <!-- your tags -->
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM