Created
June 1, 2011 12:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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