RailsCasts Pro episodes are now free!

Learn more or hide this

Fabian Becker's Profile

GitHub User: halfdan

Site: http://geekmonkey.org

Comments by Fabian Becker

Avatar

Have a read on my article Introducing Turbolinks for Rails 4.0 which a wrote a few weeks ago. It should answer your questions.

Avatar

How did you implement the caching? In the comment above I suggested using a counter_cache.

Avatar

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
def self.tag_counts
  Tag.select("tags.*, count(taggings.tag_id) as count").
    joins(:taggings).group("taggings.tag_id")
end
Avatar

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.

Avatar

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!

Avatar

Where does it store the data? Does it override internationalization files?