Created
November 6, 2012 02:17
-
-
Save keikun17/4022136 to your computer and use it in GitHub Desktop.
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
def tag_list=(tags_string, current_user) | |
self.taggings.destroy_all | |
tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq | |
tag_names.each do |tag_name| | |
tag = current_user.tags.find_or_create_by_name(tag_name) | |
tagging = self.taggings.new # <= code smell | |
tagging.tag_id = tag.id # <= code smell | |
end | |
end | |
# OR, if the post belongs to the user, then | |
def tag_list=(tags_string) | |
self.taggings.destroy_all | |
tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq | |
tag_names.each do |tag_name| | |
tag = self.user.tags.find_or_create_by_name(tag_name) | |
tagging = self.taggings.new # <= code smell | |
tagging.tag_id = tag.id # <= code smell | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
but, seriously @Dolinski, what's the deal with line 8 and 9?