2

这是我在stackoverflow中的第一个问题。

我正在使用带有名为 act as taggable 的插件的 rails 3,我喜欢它们。

我一直在从一本名为“使用 Rails 进行敏捷 Web 开发”(http://www.amazon.com/Agile-Development-Rails-Pragmatic-Programmers/dp/1934356549) 的书中做一个网上商店教程

我的“应用程序”能够过滤带有单个标签的产品,但我希望能够列出带有选择多个标签的产品。

例如,名为“Ford Ka”的产品包含标签:“Ford”、“Ka”和“red”。当我点击“福特”和“Ka”时,目录会过滤掉我所有的福特 Ka。

目前部分代码:

意见/标签/index.html.erb:

<div id="tag_cloud">
  <% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
    <%= link_to tag.name, tag_path(tag.name), :class => css_class %>
  <% end %>
</div>

意见/标签/show.html.erb

<h2>Photos tagged: <%=h params[:id] %> </h2>
<%= render 'products/catalog', :collection => @products %>

tags_controller.rb

class TagsController < ApplicationController
skip_before_filter :authorize, :only => [:show, :destroy]
  def index
    @tags = Product.tag_counts(:order => 'name')
  end

  def show
    @products = Product.tagged_with(params[:id])
      respond_to do |format|
      format.html
    format.js
    end
  end
end

谢谢!

4

0 回答 0