1
我有2種型號:如何通過與太陽黑子協會進行搜索?
class UserPrice < ActiveRecord::Base
attr_accessible :price, :product_name
belongs_to :user
belongs_to :product
searchable do
integer :product_id do
product.map(&:name)
end
end
# Associations on form like "choosing a category".
def product_name
product.name if product
end
def product_name=(name)
self.product = Product.find_or_create_by_name(name) unless name.blank?
end
end
---------------------------------------------------------------------------------
class Product < ActiveRecord::Base
attr_accessible :name
has_many :user_prices
has_many :users, :through => :user_prices
end
我想我UserPrice模型內搜索,而是由產品名稱進行搜索。這個塊在內部是如何完成的?