나는 초보자이며 muptiple 태그를 사용하여 페이지 콘텐츠를 필터링하고 싶습니다. act_as_taggable_on gem을 사용하고 있으며 태그 클라우드를 사용하고 태그에 따라 콘텐츠를 필터링했습니다. 다음 자습서 (http://railscasts.com/episodes/382-tagging)를 사용했습니다. 이제 여러 개의 tag_type을 사용하여 필터링 할 수 없었습니다. , assetType : 여러 태그를 사용하여 페이지 콘텐츠를 필터링하는 방법
는 다음 코드acts_as_taggable
acts_as_taggable_on article.rb/내 모델에 추가 된 여러 개의 태그를 작성하는 나도 몰라 컨트롤러 productType
. 나는
<div id="tag_cloud">
<% tag_cloud Article.productType_counts, %w[s m l] do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name), class: css_class %>
<% end %>
</div>
<div id="tag_cloud_asset">
<% tag_cloud Article.assetType_counts, %w[s m l] do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name), class: css_class %>
<% end %>
</div>
<div class="article-content">
<% @articles.each do |article| %>
<h3><%= article.title %></h3>
<p><%= article.content %></p>
<% end %>
을 내 _form 내가 어떻게
<%= form_for(@article) do |f| %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="field">
<%= f.label :assetType_list, "Tags (Asset Type separated by commas)" %><br />
<%= f.text_field :assetType_list %>
<%= f.label :productType_list, "Tags (Product Type separated by commas)" %><br />
<%= f.text_field :productType_list %>
</div>
<div class="actions">
<%= f.submit %>
</div>
이 가
은 누군가가 나를 도울 수있는 index.html.erb 내보기에서 다음과 같은 방법
def index
if (params[:assetType] and params[:productType])
@articles = Article.tagged_with(params[:assetType]).tagged_with(params[:productType])
else
@articles = Article.all
end
end
시도 내 컨트롤러, 색인 및 _form 페이지를 수정해야합니까? 지금은 내 모든 게시물을 보여주는 내가 태그를 클릭하면 내용이 기본 기준점으로이를 사용
대단히 감사합니다 !!!! – lucy