This limits the tags to the top 20 with the highest tag count:
tag.rb
scope :top_20, -> {
where("taggings_count != 0").order("taggings_count DESC").limit(3)
}
I want to then order those 20 according to their :id
instead of by their tagging_count
application_controller
before_action :tag_cloud
def tag_cloud
@tags = Tag.all.top_20.order(:id)
end
.order(:id)
unfortunately doesn't work. They are still showing in descending order by count.
_tags.html.erb
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag), :class => css_class %>
<% end %>
Please let me know if you need further code or explanation to help you help me :-]
The query will only take the first
order
into consideration. You can override it with reorder however this won't work in your case since it will override theorder("taggings_count DESC")
.What works for you is sort:
@tags = Tag.all.top_20.sort{ |x,y| x.id <=> y.id }