Skip to content

Instantly share code, notes, and snippets.

View pawelztef's full-sized avatar

Paweł Stefaniak pawelztef

View GitHub Profile
@pawelztef
pawelztef / application_helper.rb
Created March 20, 2018 09:11
Ruby on Rails. Class "active" for menu items based on Path or Controller and Action names
module ApplicationHelper
def active_for(options = {})
name_of_controller = options[:controller] || nil
name_of_action = options[:action] || nil
request_path = options[:path] || nil
if request_path.nil?
if (name_of_action.nil? or name_of_action == action_name) and
name_of_controller == controller_name
'active'