Rails 3标记问题,acts_as_taggable_on [英] Rails 3 tagging problems, acts_as_taggable_on

查看:100
本文介绍了Rails 3标记问题,acts_as_taggable_on的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用acts_as_taggable_on将标签添加到帖子,其他标签插件/宝石无法在rails 3上使用.我可以在帖子模型上编辑/显示标签,并且标签控制器显示按名称标记的帖子,即/tags/post-tag-name/. 我想要的功能是将帖子页面上的标签变成链接,以显示具有相同标签的其他帖子. 我在站点指南"simply rails 2"中遵循了该教程,该站点使用acts_as_taggable_on_steroids,但是我遇到了以下错误;

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

_tag.html.erb

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

posts/show.html.erb

posts/show.html.erb

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

还要尝试在标签/index.html中添加标签云,如此处所述 http://github.com/mbleigh/acts-as-taggable-on 给我一个路由错误;

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

推荐答案

您似乎想使用:collection,它将使用模板呈现整个列表:

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>

这篇关于Rails 3标记问题,acts_as_taggable_on的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆