(submenu1)
<% @functions = { "item1" => "this is the first item", "item2" => "this is second item" } %> <div class="submenu"> <div id="module-name">Point of Sale</div> <table id="submenu-table" RULES=COLS FRAME=BOX> <!-- $("#submenu-table tr:nth-child(2) td span") --> <tr style="height:0;"> <th width="20"></th> <th width="370"></th> </tr> <% @functions.each do |key, value| %> <tr> <td><span class="ylw"><%= key %></span></td> <td><span><%= value %></span></td> </tr> <% end %> </table> </div>
There will be 10 identical submenus so I'm thinking of ways to refactor this portion:
(irb snippet to refactor)
<% @functions.each do |key, value| %> <tr> <td><span class="ylw"><%= key %></span></td> <td><span><%= value %></span></td> </tr> <% end %>
What I've come up with seems a little iffy, because I can't figure out how to explicitly send in that hash instance variable as a parameter.
(refactored irb snip)
<%= render :partial => 'spit_out_submenu_items' %>
(_spit_out_submenu_items.html.erb)
<% @functions.each do |key, value| %> <tr> <td><span class="ylw"><%= key %></span></td> <td><span><%= value %></span></td> </tr> <% end %>
Edit:
I went back and tried something again and it worked for passing in the hash (I must have gotten confused with the hash declarations, they still look strange to me).
(refactored snippet)
<%= render :partial => 'spit_out_submenu_items', :locals => { :functions => @functions }%>
(partial)
<% functions.each do |key, value| %> <tr> <td><span class="ylw"><%= key %></span></td> <td><span><a href="#" class="submenu-a"><%= value %> </a></span></td> </tr> <% end %>
That's a pretty standard practice for this, right?
This post has been edited by NotarySojac: 19 January 2012 - 04:19 PM