activerecord associations do not act like a collection anymore, so convert to array first

before using map, collect, etc.
This commit is contained in:
Reinier Balt 2014-04-12 21:21:40 +02:00
parent 85cfa1c366
commit 49a09f36e8
4 changed files with 9 additions and 9 deletions

View file

@ -9,10 +9,10 @@ module IsTaggable
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings do
def to_s
self.map(&:name).sort.join(Tag::JOIN_DELIMITER)
self.to_a.map(&:name).sort.join(Tag::JOIN_DELIMITER)
end
def all_except_starred
self.reject{|tag| tag.name == Todo::STARRED_TAG_NAME}
self.to_a.reject{|tag| tag.name == Todo::STARRED_TAG_NAME}
end
end
@ -31,7 +31,7 @@ module IsTaggable
# Transactions may not be ideal for you here; be aware.
Tag.transaction do
current = tags.map(&:name)
current = tags.to_a.map(&:name)
_add_tags(list - current)
_remove_tags(current - list)
end