私は自分の coffeescript に問題を抱えていたので、代わりに ruby を使用して、クリックしたときにクラスをビューでアクティブにしたいと考えています。nav "active" というヘルパー メソッドを作成しました。ビューには、ステップごとに増加する「link」という変数があります。アイデアは、 params[:id] == link を持ち、その場合にクラスをアクティブにすることです。ただし、レールとルビーに慣れていないため、これを実装する方法がわかりません。どんな助けでも大歓迎です。
私のエラー
undefined local variable or method `link' for #<#<Class:0x007fb21e087820>:0x007fb21e53fd18>
アプリケーションヘルパーの私のメソッド
def nav_active(options = {})
return "active" if params[:id] == link
end
私の見解
<% icon= ["icon-link", "icon-bar-chart", "icon-edit", "icon-beaker","icon-link", "icon-bar-chart", "icon-edit", "icon-beaker"] %>
<% link = 0 %>
<% @step_list.each_with_index do |step, i| %>
<% case step.media_type %>
<% when 'video' %>
<% link += 1 %>
<li class="<%= nav_active %>">
<span class="glow"></span>
<a href="<%= link %>">
<i class='icon-info-sign icon-2x'></i>
<span>Video</span>
</a>
</li>
<% when 'excel' %>
<% link += 1 %>
<li class="<%= nav_active %>">
<span class="glow"></span>
<a href="<%= link %>">
<i class="<%= icon[i] %> icon-2x"></i>
<span>Step <%= i %> </span>
</a>
</li>
<% else %>
<% link += 1 %>
<li class="dark-nav <%= nav_active %> ">
<span class="glow"></span>
<a href="<%= link %>">
<i class="<%= icon[i] %> icon-2x"></i>
<span>Step <%= i %></span>
</a>
</li>
<% end %>