PROBLEM -- undefined method `-' for "books, children":String
The 'acts_as_taggable_on_steroids' has not been maintained for some time now. It used to work very well until recently. Now when I try to create or update tags, I get an error message --> undefined method `-' for "books, children":String
--- Codings ----
acts_as_taggable.rb
1. module ActiveRecord #:nodoc:
2. module Acts #:nodoc:
3. module Taggable #:nodoc:
4. def self.included(base)
5. base.extend(ClassMethods)
6. end
7. module ClassMethods
8. def acts_as_taggable
9. has_many :taggings, :as => :taggable, :dependent => :destroy
10. has_many :tags, :through => :taggings
11. before_save :save_cached_tag_list
12. after_create :save_tags
13. after_update :save_tags
14. include ActiveRecord::Acts::Taggable::InstanceMethods
15. extend ActiveRecord::Acts::Taggable::SingletonMethods
16. alias_method_chain :reload, :tag_list
::::::::::::::::::::::::
17. def save_tags
18. return unless @tag_list
19. new_tag_names = @tag_list - tags.map(&:name)
20. old_tags = tags.reject { |tag| @tag_list.include?(tag.name) }
21. self.class.transaction do
22. if old_tags.any?
23. taggings.find(:all, :conditions => ["tag_id IN (?)",
24. old_tags.map(&:id)]).each(&:destroy)
25. taggings.reset
26. end
27. new_tag_names.each do |new_tag_name|
28. tags << Tag.find_or_create_by_name(new_tag_name)
29. end
30. end
31. true
32. end
33. end
Note: The line 19 causes the problem!
tag.rb
1. class Tag < ActiveRecord::Base
2. attr_accessible :name
3. has_many :taggings, :dependent => :destroy
4. validates :name, :presence=>true
5. validates_uniqueness_of :name
6. def self.find_or_create_by_name(name)
7. Tag.where(:name=>name).first_or_create do |tag|
8. tag.name = name
9. end
10. end
Any help would be appreciated.Thank you.
where is @tag_list
created? It seems that it used to be an array and now it's a string
If you want a quick fix you could change line 19 to this:
new_tag_names = @tag_list.split(', ') - tags.map(&:name)