Skip to content

Instantly share code, notes, and snippets.

@paveltyk
Created June 1, 2011 12:41
Show Gist options
  • Save paveltyk/1002213 to your computer and use it in GitHub Desktop.
Save paveltyk/1002213 to your computer and use it in GitHub Desktop.
My solution to highlight correct menu item (using simple_navigation gem), when :create action fails
# In config/simple_navigation.rb
require 'simple_navigation/rails_controller_methods'
ActionController::Base.class_eval do
def self.disable_navigation_auto_highlighting(*args)
around_filter :temporary_disable_simple_navigation_auto_highlighting, *args
end
def temporary_disable_simple_navigation_auto_highlighting
auto_highlight = SimpleNavigation::Configuration.instance.auto_highlight
SimpleNavigation::Configuration.instance.auto_highlight = false
yield
SimpleNavigation::Configuration.instance.auto_highlight = auto_highlight
end
private :temporary_disable_simple_navigation_auto_highlighting
end
# In my controller
class Admin::SystemAlertsController < Admin::BaseController
# ...
disable_navigation_auto_highlighting :only => :create
def create
current_navigation :new_system_alert
if system_alert.save
flash[:notice] = "System alert saved!"
redirect_to :action => :index
else
render :action => :new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment