[英]Rails - Ransack - search through associations
用戶has_many個人資料和個人資料has_many電子郵件地址。 我有“用戶”搜索表,並且有“電子郵件”字段。 我該如何實現。
form_for @User.search do |U|
f.text_field :name, :name_cont
f.text_field :email, #what should I write here?
我不確定這是否是完美的方法。 您可以嘗試添加一個
has_many :email, through: profiles
用戶模型中的has_many :email, through: profiles
。 完成此操作后,您可能要做的就是:user_emails_cont
也可以嘗試:user_profiles_emails_cont
,不要有很多直通關系。
模型中的示例覆蓋:
ransacker :devices_count, formatter: proc{ |v|
data = ContractSection.csa.includes(:contract_section_devices)
.where("
(select count(*) from contract_section_devices
where contract_section_devices.contract_section_id = contract_sections.id) = #{v.to_i}
").map(&:id)
} do |parent|
parent.table[:id]
結束
視圖::devices_count_in
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.