2017-04-16 4 views
0

나는 두 개의 개별 모델 인 Articles 및 Coffeeshops에 태그를 추가하기 위해 acts_as_taggable gem을 사용하고 있습니다. 필자는 두 모델의 태그를 완벽하게 구분하여 제출하고 표시 할 수 있습니다. 태그를 클릭하면 해당 태그가 포함 된 기사 목록이 표시됩니다. 내가 해결할 수없는 것은 Coffeeshops에서이 일을하는 방법입니다. 경로는 기사 색인으로 이동합니다. 나는 내가 가진 내가 루트에서 coffeeshop/index.html.erbacts_as_taggable gem을 사용하여 두 테이블의 태그 경로 경로

routes.rb 뭔가 또한 각각의 경로를 변경해야합니다 확신 :

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 

중 하나

하지만 어떻게 내가보기에이 변경합니까 작동하지 않는 이유는 무엇입니까? 나는 현재이 있습니다 만 undefined method 'tag_path' for #<Article:0x007fd49ab18f98> Did you mean? image_path 오류가 발생했습니다 것을

<%= raw(@article.tag_list.map { |t| link_to t, @article.tag_path(t) }.join(', ')) %>하지만 : <%= raw(@article.tag_list.map { |t| link_to t, tag_path(t) }.join(', ')) %>

내가이 변경되었습니다.

답변

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