Rails 3 tagging problems, acts_as_taggable_on

僤鯓⒐⒋嵵緔 提交于 2020-01-03 04:18:04

问题


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

回答1:


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>


来源:https://stackoverflow.com/questions/4023982/rails-3-tagging-problems-acts-as-taggable-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!