Ransack搜索有很多

时间:2018-06-07 07:53:18

标签: ruby-on-rails ruby ransack

我有个人资料模型:

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

我试图在个人资料索引中使用Ransack gem来查询想要的位置。

我可以访问这些想要的位置:

profile.job_preference.wanted_locations.each do |n|
    print n.name  
end

我已阅读Ransack文档并尝试了以下各种变体:

job_preference_wanted_location_name_cont

但这似乎不起作用。

1 个答案:

答案 0 :(得分:0)

尝试

job_preferences_job_preferences_wanted_locations_wanted_location_name_cont

从个人资料,到关联(工作偏好 - 想要的位置),到想要的位置本身和名称属性。

问题在于,如果我记不起来,那么通过协会直接开展搜查工作。

相关问题