module DynamicMenu module InheritableMenus mattr_accessor :menu @@menu = Hash.new 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 def try_again? action if action == "create" return "new" elsif action == "update" return "edit" end end end end