2013-06-26 24 views
16

我想在我的主頁視圖中包含元標記。但我不想直接將它包含在application.html.erb文件的頭部分,因爲這會導致它在所有頁面中包含元標記,這些標記對於我的應用程序是冗餘的。Rails:如何在視圖中包含元標記而不是在application.html.erb中?

+0

您的主頁視圖(由你的路由定義)應該有自己的'erb'文件,你可以把他們在 – lurker

+1

我認爲類似的問題在這裏得到解答,http://stackoverflow.com/questions/10225645/rails-override-head-page-element-when-using-a-partial-or-a-specific-controll – jksloan

回答

45

你可以把

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

application.html.erb佈局head部分。

然後,鑑於要包括這些標記:

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

作爲一個單行在佈局中:<%= content_for?(:head)?產量(:頭):「」%> – Ryan

相關問題