module DynamicMenu::InheritableMenus

Public Instance Methods

get_current_menu() click to toggle source
# File lib/dynamic_menu/inheritable_menus.rb, line 5
def get_current_menu
  path = Rails.root.join('app/menus')
  full_path = path + "#{params[:controller]}/#{params[:action]}.rb"
  second_chance = path + "#{params[:controller]}/#{try_again? params[:action]}.rb"
  logger.debug("Dynamic Menu:\n\r\tFirst Chance: #{params[:action]}\n\r\tSecond Chance: #{try_again? params[:action]}")
  if File.exists?(full_path)
    load full_path
    "#{params[:action]}_menu".classify.constantize.new(self)
  elsif File.exists?(second_chance)
  #Depending on the action (for example edit) it should look for a relationship (:create=:new or :update=:edit
    load second_chance
    "#{try_again? params[:action]}_menu".classify.constantize.new(self)
  end
end
try_again?(action) click to toggle source
# File lib/dynamic_menu/inheritable_menus.rb, line 20
def try_again? action
  if action == "create"
     return "new"
   elsif action == "update"
     return "edit"
  end
end