Assuming that a tag should only be created once (unique constraint on name) I'd rather use:
ruby
self.tags = names.split(",").map do |n|
Tag.find_or_create_by_name(n.strip)
end
instead of
ruby
self.tags = names.split(",").map do |n|
Tag.where(name: n.strip).first_or_create!
end
For better performance one should also consider a counter cache on the belongs_to :tags in the taggings model. This would avoid the join when calculating the tag counts in:
ruby
defself.tag_countsTag.select("tags.*, count(taggings.tag_id) as count").
joins(:taggings).group("taggings.tag_id")
end
Shouldn't the assignment of self.tags in the method tag_names= be moved to an after_save callback method? What if the validations on a newly created article fail? The tags would still be created without proper referencing.
If you'd like to read more about Turbolinks check http://geekmonkey.org/articles/28-introducing-turbolinks-for-rails-4-0
Have a read on my article Introducing Turbolinks for Rails 4.0 which a wrote a few weeks ago. It should answer your questions.
How did you implement the caching? In the comment above I suggested using a counter_cache.
Assuming that a tag should only be created once (unique constraint on name) I'd rather use:
instead of
For better performance one should also consider a counter cache on the
belongs_to :tags
in the taggings model. This would avoid the join when calculating the tag counts in:Shouldn't the assignment of
self.tags
in the methodtag_names=
be moved to an after_save callback method? What if the validations on a newly created article fail? The tags would still be created without proper referencing.Ryan, is that a video rendering error at the end where you try to switch to "/-l" in vim? It looks like the video lags for a while.
Other than that, very nice intro to dalli!
Where does it store the data? Does it override internationalization files?