Last active
August 29, 2015 13:56
-
-
Save FineLineAutomation/8978601 to your computer and use it in GitHub Desktop.
Scoping based on whether we are in spree's admin backend or not.
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
#Make sure this appears somewhere in your application.rb file. | |
config.to_prepare do | |
# Load application's model / class decorators | |
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| | |
Rails.configuration.cache_classes ? require(c) : load(c) | |
end | |
# Load application's view overrides | |
Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c| | |
Rails.configuration.cache_classes ? require(c) : load(c) | |
end | |
end |
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
#put in app/controllers/spree/base_controller_decorator.rb | |
Spree::BaseController.class_eval do | |
before_filter :store_path_in_thread | |
def store_path_in_thread | |
Thread.current[:path] = request.original_url | |
end | |
end |
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
Spree::Taxon.class_eval do | |
scope :with_children, :conditions => "parent_id is null OR #{self.table_name}.id IN (SELECT taxon_id FROM spree_products_taxons)" | |
def self.scope_based_on_path | |
path = Thread.current[:path] | |
if path.nil? or path.include? "admin" | |
order("#{self.table_name}.position") | |
else | |
#binding.pry | |
with_children | |
#order("#{self.table_name}.position") | |
end | |
end | |
scope :base_on_path, lambda { scope_based_on_path } | |
default_scope -> { base_on_path } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment