两个content_for在所有视图中呈现相同的yield(Rails 3)



我有两个独立的视图,它们正在输出名为:icons的命名yield块的内容。

当我加载这两个页面时,我总是在:图标中看到阻止2个视图的内容…:-(

视图1:项目#索引

<% content_for :icons do %>
    Project Icons ...
<% end %>
...

视图2:树#显示

<% content_for :icons do %>
  <a href="javascript:void(0)" id="dynatree-expand-all">Expand</a> 
  <a href="javascript:void(0)" id="dynatree-collapse-all">Collapse</a> 
  <a href="javascript:void(0)" id="dynatree-transfer">Import</a> 
  <div id="viewname_selector">
    <%= form_tag({:controller => :loopview, :action => :show}, { :id => "viewname_form" ,:remote => true}) do %>
        <%= collection_select(:viewname, :id, @viewnames, :id, :name, :selected => @current_viewname_id) %>
    <% end %>
  </div>
<% end %>

application.html.erb中的调用是

<div id="icons">
  <%= yield :icons %>
</div>

当我加载Projects#索引时,我只有项目图标(所以这是可以的)。

当我加载Tree#索引时,我有树图标和项目图标。。。

我做错了什么?如何在树视图中只获取树图标?

编辑:树#索引的完整来源

<% content_for :head do %>
<title>Dynatree View <%= sicadea %></title>
<%= javascript_include_tag "leanModal/jquery.leanModal.min" %>  
<%#   For the dynatree  %>
<%= stylesheet_link_tag    "dynatree/skin/ui.dynatree.css" %>
<%= stylesheet_link_tag    "dynatree/skin/ui.dynatree.custom.css" %>
<%= javascript_include_tag "cookie/jquery.cookie.js" %>
<%= javascript_include_tag "dynatree/jquery.dynatree-1.2.4.js" %>
<%= stylesheet_link_tag    "contextMenu/jquery.contextMenu.css" %>
<%= javascript_include_tag "contextMenu/jquery.contextMenu-custom.js" %>
<%= javascript_include_tag "contextMenu/jquery.ui.position.js" %>
<%= javascript_include_tag "dynatree.js" %>
<%# for the poin'ts table %>
<%= stylesheet_link_tag    "loopview.css" %>
<% end %>
<% content_for :icons do %>
<a href="javascript:void(0)" id="dynatree-expand-all">Expand</a>  |
<a href="javascript:void(0)" id="dynatree-collapse-all">Collapse</a>  |
<a href="javascript:void(0)" id="dynatree-transfer">Import</a> |
<div id="viewname_selector">
    <%= form_tag({:controller => :loopview, :action => :show}, { :id => "viewname_form" ,:remote => true}) do %>
        <%= collection_select(:viewname, :id, @viewnames, :id, :name, :selected => @current_viewname_id) %>
    <% end %>
</div>
<% end %>

<div id="leftpanel">
<!-- Leftpanel Context menus -->
<ul id="myMenu" class="contextMenu">
    <li class="rename"><a href="#rename">Rename</a></li>
    <li class="new_child"><a href="#new_child">New Child</a></li>
    <li class="copy"><a href="#copy">Copy</a></li>
    <li class="paste"><a href="#paste">Paste</a></li>
    <li class="delete"><a href="#delete">Delete</a></li>
</ul>
<ul id="ProjectMenu" class="contextMenu">
    <li class="new_child"><a href="#new_child">New Child</a></li>
</ul>
<!-- Leftpanel Tree title -->
<div id='dynatree-title' data-project-id='<%= current_project.id %>'>
    <span></span><%= current_project.name %>
</div>
<!-- Leftpanel Dynatree -->
<%= render_project_tree(current_project, "tree") %> 
<!-- Leftpanel "New Child" Form -->
<%= render :partial => "lean_new_child" %>
</div>

<!-- Right Panel -->
<div id="dynatree-details">
    <%= render :template => 'projects/show' %>
</div>

请问您为什么在application.html.erb.中添加以下代码

<div id="icons">
  <%= yield :icons %>
</div>

我认为这也只加载在您的Tree#index页面中。。

最新更新