我正在使用acts_as_taggable gem将标记添加到两个单独的模型文章和咖啡快车。我有能力分别完美地提交和显示两个模型中的标签。当你点击标签时,它也会显示一个包含那个标签的文章列表,非常棒。我无法解决的是如何为咖啡店做到这一点。该路径将带您到文章索引。我确信我将需要改变routes.rb
的东西,也是个别路径coffeeshop/index.html.erb
使用acts_as_taggable的两个表中标记的路径路径gem
在路线我:
get 'tags/:tag', to: 'articles#index', as: :tag
复制此为咖啡店显然是行不通的。我沿线的思考:
get 'tags/:article_tag, to 'articles#index, as: article_tag
get 'tags/:coffeeshop_tag, to 'coffeeshops#index, as: coffeeshop_tag
get 'articles/tags/:article_tag, to 'articles#index, as: article_tag
get 'coffeeshops/tags/:coffeeshop_tag, to 'coffeeshops#index, as: coffeeshop_tag
无法正常工作或
但我怎么改变这个的看法?我目前有: <%= raw(@article.tag_list.map { |t| link_to t, tag_path(t) }.join(', ')) %>
我把它改为:
<%= raw(@article.tag_list.map { |t| link_to t, @article.tag_path(t) }.join(', ')) %>
但只有扔undefined method 'tag_path' for #<Article:0x007fd49ab18f98> Did you mean? image_path
错误。