Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Tomaž Zaman's Profile

GitHub User: carmivore

Site: https://codeable.io

Comments by Tomaž Zaman

Avatar

If there was a railscast I'd wish it was covered with tests, then this is the one.

Avatar

Your opinion on this is correct, it's just not worth the effort because all of the restrictions on concurrent connections. After trying many possibilities (ActionController::Live, Socket.io, Faye,... ) we decided to outsource the real-time component entirely to pusher.com - highly recommended. It takes literally minutes to set up and you don't have to worry about updating, uptime, compatibilities, scaling...

(disclaimer: not affiliated to Pusher in any way)

Avatar

Thank you for the video. I must admit though, I'm not a fan of this approach - numerous experiments have proved that this approach doesn't really improve conversions.

Avatar

Same problem here

EDIT: solved, first you need to add id and name columns to group

ruby
def self.tag_counts
    Tag.select("tags.id, tags.name, count(taggings.tag_id) as count").
      joins(:taggings).group("taggings.tag_id, tags.id, tags.name")
  end

then you need to coerce the count into an integer in the helper:

ruby
def tag_cloud(tags, classes)
    max = tags.sort_by(&:count).last
    tags.each do |tag|
      index = tag.count.to_f / Integer(max.count) * (classes.size - 1)
      yield(tag, classes[index.round])
    end
  end