如何渲染特定次数?我正在使我的顶部菜单和侧面菜单具有相同的页面。我希望顶部菜单仅显示前 4 页,而侧面菜单则显示所有可用页面。
<%= 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>