【发布时间】:2013-10-28 08:48:21
【问题描述】:
我尝试了所有可以在网上找到的组合,但总是失败。
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
【问题讨论】:
-
您不能在班级级别执行
unless match.present?,因为您在这里没有使用特殊的 Profile 实例。匹配的不是 Profile 类,而是配置文件实例。 -
@OlivierElMekki 那么如何使用 lambda 呢?
-
我自己不使用 sunspot,但它似乎可以处理通过 proc as :if option 的条件索引。
标签: ruby-on-rails associations ruby-on-rails-4 rails-activerecord sunspot-solr