module Selected
Public Instance Methods
selected?(controller_name, action_name="", id="")
click to toggle source
# File lib/selected.rb, line 2 def selected?(controller_name, action_name="", id="") if controller_matches(controller_name) && action_matches(action_name) && params[:id] == id if defined? SELECTED_CLASS_NAME SELECTED_CLASS_NAME else 'active' end end unless action_name.present? action_name = params[:action] end unless id.present? id = params[:id] end if controller_matches(controller_name) && action_matches(action_name) && params[:id] == id if defined? SELECTED_CLASS_NAME SELECTED_CLASS_NAME else 'active' end end end
Private Instance Methods
action_matches(action_name)
click to toggle source
# File lib/selected.rb, line 36 def action_matches(action_name) (action_name.respond_to?(:each) && action_name.map(&:to_s).include?(params[:action])) || params[:action] == action_name.to_s end
controller_matches(controller_name)
click to toggle source
# File lib/selected.rb, line 28 def controller_matches(controller_name) if controller_name.is_a?(Regexp) controller_name =~ params[:controller] else controller_name.to_s == params[:controller] end end