ruby on rails - Trying to have a view & block have access to a variable from a another block that is used to determine which element number in array -


i newer rails: side navigation partial takes each step , provides icon , link it. current active step, have same icon in top navigation side navigation. however, <%= icon[i] %> not work since [i] comes different block in different view. how make active link top's navigation has same icon[i] side navigation without having access i? see below.

_side_navigation.html.erb

  <% icon= ["icon-link", "icon-bar-chart", "icon-edit", "icon-beaker","icon-link", "icon-bar-chart", "icon-edit", "icon-beaker"] %>       <% @step_list.each_with_index |step, i| %>      <% case step.media_type %>     <% when 'video' %>             <li class="<%= nav_active step %>">               <a href = "                   <i class='icon-info-sign icon-2x'></i>                   <span>video</span>                 </a>             </li>       <% when 'excel' %>             <li class="<%= nav_active step %>">                   <i class="<%= icon[i] %> icon-2x"></i> **<<i need [i] in other partial know element of array chosen**                   <span>step <%= %> </span>               </a>             </li>      <% else %>             <li class="<%= nav_active step %>">                   <i class="<%= icon[i] %> icon-2x"></i>                   <span>step <%= %></span>               </a>             </li>      <% end %>      <% end %> 

_top_navigation.html.erb

<div class="area-top clearfix">         <div class="pull-left header">                 <% case @step.media_type %>               <% when 'video' %>                 <h3 class="title">                   <i class="<%= icon[i] %>"></i></i> <<<here problem since, not have access current "i" other block                   video                 </h3>                 <h5>                   video course here                 </h5>                <% when 'excel' %>                <h3 class="title">                 <i class="<%= icon[i] %>"></i></i>               excel             </h3>             <h5>               please use excel sheet below complete challenge.             </h5>           <% else %>            <h3 class="title">             <i class="<%= icon[i] %>"></i></i>               multiple choice                                           </h3>             <h5>               please choose selection below             </h5>           <% end %>      </div> 

is there no natural order these steps? don't have 'i' can pass in when include partial (partial local variables)?

if not, sounds need smarter 'step' object aware of index in workflow.

you place icon list in helper, so:

def icons   ["icon-link", "icon-bar-chart", "icon-edit",    "icon-beaker","icon-link", "icon-bar-chart",    "icon-edit", "icon-beaker"] end 

gets out of view.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -