ruby - Do I need an Enumerator for this? -


i want this:

<div class="menu">    <%- render_menu |title,path,children| %>      <%= link_to title, path %>      <div class="submenu">       <%= render_menu(children) |title,path,children| %>         <%= link_to title, path %>         <%= children %>       <%- end %>     </div>    <% end %>  </div> 

the method render_menu this:

def render_menu(children=nil)   children = paths.roots if children.nil?   children.collect |child|     [ child.title, child.path, child.children ]   end end 

i'm not sure render_menu needs return 3 params.. render_menu grab default menu items if no argument given..

you have use yield , replace each collect inside render_menu:

def render_menu(children=nil)   children = paths.roots if children.nil?   children.each |child|     yield([child.title, child.path, child.children])   end end 

you should modify template not display value returned render_menu:

<div class="submenu">     <% render_menu(children) |title,path,children| %>         <%= link_to title, path %>         <%= children %>     <% end %> </div> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -