nav_link

in app/helpers/application_helper.rb [43:77]


  def nav_link(options = {}, &block)
    if path = options.delete(:path)
      if path.respond_to?(:each)
        c = path.map { |p| p.split('#').first }
        a = path.map { |p| p.split('#').last }
      else
        c, a, _ = path.split('#')
      end
    else
      c = options.delete(:controller)
      a = options.delete(:action)
    end

    if c && a
      
      klass = current_controller?(*c) && current_action?(*a) ? 'active' : ''
    else
      
      klass = current_controller?(*c) || current_action?(*a) ? 'active' : ''
    end

    
    
    o = options.delete(:html_options) || {}
    o[:class] ||= ''
    o[:class] += ' ' + klass
    o[:class].strip!

    if block_given?
      content_tag(:li, capture(&block), o)
    else
      content_tag(:li, nil, o)
    end
  end