Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix that if Admin::ProductsController doesnt already have a hook defi…

…ned for create.before, as is the case in latest spree, an exception was raised when trying to add :set_stores with << because create.before returned nil, not an empty array
  • Loading branch information...
commit 9313fdc7a50e6ac5213c52a51d655c1f46e6c055 1 parent d59cc5a
@davidnorth davidnorth authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 multi_domain_extension.rb
View
23 multi_domain_extension.rb
@@ -127,3 +127,26 @@ def self.current
# end
end
end
+
+
+# Make it possible to add to existing resource controller hooks with '<<' even when there's no hook of a given type defined yet.
+# e.g. create.before << :assign_to_store
+ResourceController::Accessors.module_eval do
+ private
+ def block_accessor(*accessors)
+ accessors.each do |block_accessor|
+ class_eval <<-"end_eval", __FILE__, __LINE__
+
+ def #{block_accessor}(*args, &block)
+ @#{block_accessor} ||= []
+ unless args.empty? && block.nil?
+ args.push block if block_given?
+ @#{block_accessor} = [args].flatten
+ end
+ @#{block_accessor}
+ end
+
+ end_eval
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.