1

您如何按小数或日期字段排序?

class CreateUserPrices < ActiveRecord::Migration

  def self.up
    create_table :user_prices do |t|
      t.decimal :price, :precision => 8, :scale => 2
      t.date :purchase_date
      t.timestamps
    end
  end
end

我正在尝试按价格和购买日期对我的用户价格进行排序。


searchable do
  text :product_name do
    product.name
  end
  # field for :price?
  # field for :purchase_date?
end

模型中有什么?

4

1 回答 1

0

确保在将任何新代码添加到您的searchable do块时rake sunspot:reindex

decimal字段使用浮点数date字段使用时间

searchable do
  text :product_name do
    product.name
  end
  time :purchase_date
  float :price
end
于 2011-11-20T12:04:41.333 回答