ruby-on-railsacts-as-taggableacts-as-taggable-on

Rails 3 tagging problems, acts_as_taggable_on


I'm using acts_as_taggable_on to add tags to posts, other tagging plugins/gems don't work with rails 3. I can edit/display tags on the post model and the tags controller displays the posts tagged by name i.e /tags/post-tag-name/. The functionality I want is to turn the tags on the posts pages into links to display the other posts with the same tag. I followed the tutorial in sitepoints 'simply rails 2' which uses acts_as_taggable_on_steroids but I'm stuck with the following error;

ActionView::MissingTemplate in Posts#show 
Missing partial acts_as_taggable_on/tags/tag with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "../app/views"

Extracted source (around line #28):

25:  <div id="tags">
26:  <% unless @post.tag_list.empty? %>
27:  <p class="tags">
28:  <%= render :partial => @post.tags %></p>
29:  <% end %>

...

class Post < ActiveRecord::Base
  ...
  acts_as_taggable_on :tags
end



class TagsController < ApplicationController
      def show
        @post = Post.tagged_with(params[:id])
      end
end

_tag.html.erb

<%= link_to, tag_path(:id => tag.name) %>

posts/show.html.erb

<div id="tags">
 <% unless @post.tag_list.empty? %>
 <p class="tags">
 <%= render :partial => @post.tags %></p>
 <% end %>
 </div>

Also trying to add a tag cloud at tags/index.html as described here http://github.com/mbleigh/acts-as-taggable-on gives me a routing error of;

No route matches {:action=>"tag", :id=>"news", :controller=>"tags"}

Solution

  • Looks like you want to use :collection, which will render the whole list with the template:

    <div id="tags">
      <% unless @post.tag_list.empty? %>
        <p class="tags">
          <%= render :partial => 'tag', :collection => @post.tags %>
        </p>
      <% end %>
    </div>