09 September 2008

has_many_polymorphs regression after the upgrade to Rails 2.1.1

vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/dependencies.rb:8: Dependencies is not a module (TypeError)

This is dued to a Rails 2.1.1 refactoring in the location of the ActiveSupport::Dependencies module.
Copy paste the following code to your /has_many_polymorphs/lib/has_many_polymorphs/dependencies.rb to fix the problem:


module ActiveSupport
module Dependencies

mattr_accessor :injection_graph
self.injection_graph = Hash.new([])

# Add a dependency for this target.
def inject_dependency(target, *requirements)
target, requirements = target.to_s, requirements.map(&:to_s)
injection_graph[target] = ((injection_graph[target] + requirements).uniq - [target])
requirements.each {|requirement| mark_for_unload requirement }
_logger_debug "injection graph: #{injection_graph.inspect}" if Dependencies.log_activity
end

# Make sure any dependent constants of the constants added by yield are reloaded.
def new_constants_in_with_injection(*descs, &block) # chain

if Dependencies.log_activity
_logger_debug "autoloaded constants: #{autoloaded_constants.inspect}"
_logger_debug "explicitly unloadable constants: #{explicitly_unloadable_constants.inspect}"
end

returning(new_constants_in_without_injection(*descs, &block)) do |found|
_logger_debug "new constants: #{found.inspect}" if Dependencies.log_activity and found.any?
found.each do |constant|
injection_graph[constant].each do |requirement|
requirement.constantize
_logger_debug "constantized #{requirement}" if Dependencies.log_activity
end
end
end
end
alias_method_chain :new_constants_in, :injection

end
end



I am using the plugin has_many_polymorphs to manage tags in languages. An event has a category which is in reality a tag we translate in 7 languages ...

I inherited this plugin from the previous developper and I am looking forward to replace it by acts_as_taggable_on_steroids !

No comments: