views:

30

answers:

1

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"}
A: 

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>
numbers1311407
SyntaxError in Posts#show Showing ../app/views/tags/_tag.html.erb where line #1 raised: ../app/views/tags/_tag.html.erb:1: syntax error, unexpected ')', expecting tCOLON2 or '[' or '.' ...to, tag_path(:id => tag.name) );@output_buffer.to_s ... ^ ../app/views/tags/_tag.html.erb:2: syntax error, unexpected keyword_ensure, expecting ')' ..app/views/tags/_tag.html.erb:4: syntax error, unexpected keyword_end, expecting ')' Extracted source (around line #1): 1: <%= link_to, tag_path(:id => tag.name) %>
raphael_turtle
your link_to is wrong, you're not linking to anything. needs to be:<%= link_to tag.name, tag_path(:id => tag.name) %>
numbers1311407
thanks, a silly thing to overlook, but I still have the tag cloud error
raphael_turtle
well the code they show on the acts_as_taggable_on homepage isn't complete. it assumes you're writing the "tag" method for the cloud. If, e.g. you just removed the "tag" action from the example link, e.g.: <%= link_to tag.name, { :id => tag.name }, :class => css_class %> then it would link to the #show action for the current page and should work (on the #show view). However you probably have a deeper problem, in that Post.tagged_with(:id) is returning a set, not a Post.
numbers1311407
that gives me links to "tags?id=news", not to "tags/news" I thought <%= link_to tag.name, (:class => css_class), tag_path(:id => tag.name)%> should work but it doesn't...
raphael_turtle
you're close, should probably just be tag_path(tag). Also in that last example the html options needs to come after the URL parameter, not before.
numbers1311407
so <%= link_to tag.name, tag_path(tag), :class => css_class %> give me "tags/1", the id of each tag
raphael_turtle
sorry, tag_path(tag.name), or open up ActsAsTaggableOn::Tag and "def to_param; name end"
numbers1311407
I already tried tag_path(tag.name) but I got the error "No route matches {:action=>"destroy", :controller=>"tags", :id=>"news"}
raphael_turtle
thanks for all the help by the way..
raphael_turtle
I added the method to tag.rb but it makes no difference, I still the same error
raphael_turtle
tag_path(tag.name) is working, I deleted the tags then entered new ones and it works. Thanks!
raphael_turtle
NP glad to help.
numbers1311407