Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:48:31+00:00 2026-06-09T20:48:31+00:00

I’m very new to Ruby on Rails, so there’s probably a simple solution I’m

  • 0

I’m very new to Ruby on Rails, so there’s probably a simple solution I’m missing.

The tldr version – how do I display an Acts As Taggable On tag cloud of distinct (i.e. no repeating) tags assigned to all instances of a particular model on that model’s index page?

The longer version – I have a model called Video in which I have successfully managed to implement a tagging feature using Acts as Taggable On and this fantastic tutorial.

What I’d like to do now is, on the Video’s index page (index.html.erb), to display a summary of all the individual tags that a user has assigned to individual videos. For example, lets say I have three videos, each tagged as follows:

Video 1: great, banana, book
Video 2: small, great, apple
Video 3: rubbish, small, banana

I’d like the index page to display the following list of tags:

great, banana, book, small, apple, rubbish.

The code for my model (elided) is as follows:

class Video < ActiveRecord::Base

attr_accessible :tag_list # Lots of other fields in here as well, but not relevant

acts_as_taggable_on :tags

end

The code in my Video helper is as follows:

module VideosHelper

  include ActsAsTaggableOn::TagsHelper

end

Finally, as per the gem’s documentation, I’ve added the following code to my controller:

class VideosController < ApplicationController
  def tag_cloud
    @tags = Video.tag_counts_on(:tags)
  end
end

So, what code should I be adding to the index page of my view? I tried the following, again as per the documentation:

<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
  <%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
<% end %>

But this returns the following error when I go to the Video index page:

undefined method `empty?' for nil:NilClass

As I say, I’m obviously missing something simple, but I’m completely new to Rails (and Ruby) so I’m still finding my feet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:48:31+00:00Added an answer on June 9, 2026 at 8:48 pm

    OK, after hacking about a bit, I think I’ve found a solution, in case anyone else wondering how to do this happens to stumble across this question.

    However, please be aware that I am very much a beginner at RoR, so this is probably not the best solution – if I’m doing anything wrong, or if you have a better solution, feel free to let me know!

    Add this code in your view to display the list of tags for a particular model in order:

    @tags = ActsAsTaggableOn::Tag.all(:order=>'name')
    
    <% if @tags.count > 0 %>
      <ul>
        <% @tags.each do |tag| %>
          <li><%= link_to tag.name, tagged_url(:tag => tag.name) %></li>
        <% end %>
      </ul>
    <% else %>
      <p>There are no tags on the system.</p>
    <% end %>
    

    This results in a very basic display and, due to my inexperience I advise using this approach with caution – I’m sure it’s not the best, or even the “safest”, method, so beware!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.