Skip to content

Instantly share code, notes, and snippets.

@keikun17
Created November 6, 2012 02:17
Show Gist options
  • Save keikun17/4022136 to your computer and use it in GitHub Desktop.
Save keikun17/4022136 to your computer and use it in GitHub Desktop.
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
@keikun17
Copy link
Author

keikun17 commented Nov 6, 2012

but, seriously @Dolinski, what's the deal with line 8 and 9?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment