Reputation: 27232
I have 2 models:
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
I want to search inside of my UserPrice model but search by the Products name. How is that done inside of the block?
Upvotes: 1
Views: 1213
Reputation: 2230
class UserPrice < ActiveRecord::Base
belongs_to :product
searchable do
text :product_name do
product.name
end
end
end
Upvotes: 4