[英]Ransack search has many through
我有一个Profile模型:
has_one :job_preference, inverse_of: :profile, dependent: :destroy
accepts_nested_attributes_for :job_preference, reject_if: :all_blank, allow_destroy: true
工作偏好模型:
belongs_to :profile
has_many :job_preferences_wanted_locations
has_many :wanted_locations, through: :job_preferences_wanted_locations, dependent: :destroy
想要的工作偏好位置模型:
class JobPreferencesWantedLocation < ApplicationRecord
belongs_to :job_preference
belongs_to :wanted_location
accepts_nested_attributes_for :wanted_location
end
所需地点模型:
class WantedLocation < ApplicationRecord
has_many :job_preferences_wanted_locations
has_many :job_preferences, through: :job_preferences_wanted_locations, dependent: :destroy
end
我试图在Profile索引中使用Ransack gem来查询所需位置。
我可以像这样访问这些所需的位置:
profile.job_preference.wanted_locations.each do |n|
print n.name
end
我已经阅读了Ransack文档,并尝试了以下方法的变体:
job_preference_wanted_location_name_cont
但这似乎不起作用。
尝试
job_preferences_job_preferences_wanted_locations_wanted_location_name_cont
从个人资料到关联(工作偏好-所需位置),再到所需位置本身和名称属性。
关键是,如果我不记得不好的话,则不能通过关联直接使用ransack。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.