Skip to content

Instantly share code, notes, and snippets.

@kawahiro311
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawahiro311/d12b2761353da92b3324 to your computer and use it in GitHub Desktop.
Save kawahiro311/d12b2761353da92b3324 to your computer and use it in GitHub Desktop.
Railsでナビゲーションの現在地をアクティブにする
<ul class="nav">
<li class="<%= active_class_for('controller1') %>"><a href="#">Controller1</a></li>
<li class="<%= active_class_for('controller2') %>"><a href="#">Controller2</a></li>
<li class="<%= active_class_for('controller3') %>"><a href="#">Controller3</a></li>
</ul>
module ApplicationHelper
def active_class_for controller_name
'active' if params[:controller] == controller_name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment