如何呈现特定次数? 我正在制作我的topmenu和sidemenu有相同的页面。我希望topmenu只显示前4页,并且sidemenu显示所有可用的页面。
<%= render :partial => '/shared/menu_branch', :collection => roots, :locals => {
:hide_children => hide_children,
:sibling_count => (roots.length - 1),
:apply_css => true
} -%>
和menu_branch
<%
if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
css = "class='#{classes.join(' ')}'".html_safe
end
dom_id = "id='item_#{menu_branch_counter}'".html_safe if menu_branch.parent_id.nil?
-%>
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to menu_branch.title, menu_branch.url -%>
</li>
这是我想要渲染4次的线。
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to menu_branch.title, menu_branch.url -%>
</li>
答案 0 :(得分:1)
好吧,我自己想通了。这是我改变的代码。
<%= render :partial => '/shared/menu_branch', :collection => roots.select{|p|roots.rindex(p) < 4}, :locals => {
:hide_children => hide_children,
:sibling_count => (roots.length - 1),
:apply_css => true
} -%>
这是我添加的内容。
:collection => roots.select{|p|roots.rindex(p) < 4},