我尝试了所有可以在网上找到的组合,它总是失败。
class Profile < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
has_one :match # educational matches
accepts_nested_attributes_for :match
attr_accessor :form
unless match.present?
searchable do
integer :id
string :country
string :state
end
end
end
和
Match belongs_to :profile
我在Profile模型中尝试:
unless profile.match.exist? (does profile have a match association existing?)
.. do something
end
答案 0 :(得分:2)
受the blog post that Olivier linked to和confirmed in the Sunspot documentation的启发,你可以这样做:
# In your Profile model
searchable :if => proc { |profile| profile.match.present? } do
integer :id
string :country
string :state
end