RailsCasts Pro episodes are now free!

Learn more or hide this

Paulina's Profile

GitHub User: paulinag

Site: www.Drivenorganization.com

Comments by Paulina

Avatar

in case someone had this issue - in the end I have Tomaž Zaman solution with the helper method modification as below:

ruby
def tag_cloud(tags, classes)
    max = 0
    tags.each do |t|
      if t.count.to_i > max
        max = t.count.to_i
      end 
    end
    tags.each do |tag|
      index = tag.count.to_f / max * (classes.size - 1)
      yield(tag, classes[index.round])
    end
  end 
Avatar

I used this code, and it works but only if there are few tags.

Problem is that count is not a number so
max = tags.sort_by(&:count).last
doesn't sort it properly when number of tags is more than 9 for specific post/article.

I will try to write function to find max properly unless anyone has an idea how to have it as a number in the first place..

Avatar

worked like a charm :) Thank you!!

Avatar

it is not working for me as well..
I get the error:

PGError: ERROR: column "tags.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT tags.*, count(taggings.tag_id) as count FROM "tags" I...

Can anyone help with that?

Avatar

ah I was looking for this for half a day! :) Thank you!!

Avatar

Adrian - thank you! this is exactly what I needed (I have a bit different routes).

and for me (starting with rails) verbose is an awesome feature :)

Avatar

Thank you for answering yourself as this is just what I was looking for :)