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

时间:2013-08-27 09:48:40

标签: ruby-on-rails render yield content-for

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

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

查看1:项目#Index

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

查看2:Tree#Show

<% 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#index时,我只有Project Icons(所以没关系)。

当我加载Tree #index时,我有树图标和项目图标......

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

编辑:树的完整来源#index

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

1 个答案:

答案 0 :(得分:0)

我可以知道您为什么在application.html.erb中添加以下代码。

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

我认为这只会加载到Tree#index页面中。