Usage:
%li{:class => active_class(:c => 'controller_name',:a => ['action1','action2'],:id => @object.id) }
= link_to some_path do
%i.fa.fa-chevron-circle-right.fa-fw
%span Link Name| module ApplicationHelper | |
| # Given the options, this method determines whether the css class 'active' can be applied to the caller in the sidenav. | |
| # options[:c] - controller | |
| # options[:a] - action | |
| # options[:id] - id of an object | |
| def active_class options | |
| active = | |
| (!options[:c] || (options[:c] == params[:controller])) && | |
| (!options[:a] || (options[:a].include? params[:action])) && | |
| (!options[:id] || (options[:id].to_s == params[:id])) | |
| active ? 'active' : false | |
| end | |
| end |