How to render specific number of times ? I'm making that my topmenu and sidemenu have the same pages.I want for the topmenu to only show first 4 pages and for the sidemenu to show all available pages.
如何呈现特定次数?我正在使我的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
} -%>
and the menu_branch
和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>
this is the line i want to render only 4 times.
这是我想要渲染4次的线。
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to menu_branch.title, menu_branch.url -%>
</li>
1 个解决方案
#1
1
Alright I figured out it by my self. This is the code I changed.
好吧,我自己想通了。这是我改变的代码。
<%= 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
} -%>
this is what I added.
这就是我添加的内容。
:collection => roots.select{|p|roots.rindex(p) < 4},
#1
1
Alright I figured out it by my self. This is the code I changed.
好吧,我自己想通了。这是我改变的代码。
<%= 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
} -%>
this is what I added.
这就是我添加的内容。
:collection => roots.select{|p|roots.rindex(p) < 4},