在 index_path 路由上传递参数
Pass params on index_path route
我有一个助手可以显示 post
的标签
# 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
我该如何解决这个问题?作为旁注,我尝试从中复制的侧边栏代码(我列出了所有 post-标签)工作正常
- tag_cloud Post.tag_counts, %w(tag) do |tag, css_class|
= link_to tag.name, posts_path(tag: tag.name), :class => css_class
post.tag_list
会给你一个标签数组作为字符串。
您正在寻找的可能是 post.tags
,它应该 return 一个 ActsAsTaggableOn
对象的数组。
我有一个助手可以显示 post
的标签# 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
我该如何解决这个问题?作为旁注,我尝试从中复制的侧边栏代码(我列出了所有 post-标签)工作正常
- tag_cloud Post.tag_counts, %w(tag) do |tag, css_class|
= link_to tag.name, posts_path(tag: tag.name), :class => css_class
post.tag_list
会给你一个标签数组作为字符串。
您正在寻找的可能是 post.tags
,它应该 return 一个 ActsAsTaggableOn
对象的数组。