【问题标题】:Pass params on index_path route在 index_path 路由上传递参数
【发布时间】:2017-03-26 19:46:34
【问题描述】:

我有一个显示帖子标签的助手

# Show action
%p Tags #{ link_tags @post }

# Helper
def link_tags post
  raw post.tag_list.map{ |t| 
    link_to t, posts_path(tag: t.name)
  }.join(', ')
end

但是我在屏幕上遇到错误

undefined method `name' for "ruby":String

我该如何解决这个问题?作为旁注,我试图从中复制的侧边栏(我列出所有帖子标签)上的代码可以正常工作

- tag_cloud Post.tag_counts, %w(tag) do |tag, css_class|
    = link_to tag.name, posts_path(tag: tag.name), :class => css_class

【问题讨论】:

    标签: ruby-on-rails parameters routes link-to acts-as-taggable-on


    【解决方案1】:

    post.tag_list 会给你一个标签数组作为字符串。

    您正在寻找的可能是post.tags,它应该返回一个ActsAsTaggableOn 对象的数组。

    这里有tutorial about tags on posts

    【讨论】:

      猜你喜欢
      • 2021-08-13
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      • 2022-10-02
      相关资源
      最近更新 更多