2017-04-16 47 views
0

我正在使用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錯誤。

回答

0

對其進行排序。

更新視圖標籤:

<%= raw(@coffeeshop.tag_list.map { |t| link_to t, coffeeshops_tag_path(t) }.join(', ')) %>

和改變,如下路線:

get 'coffeeshops/tags/:tag', to: 'coffeeshops#index', as: :coffeeshops_tag