[英]How to implemet search with ransack on a has_many :through association
[英]Ransack: Search has_many through association
我是Rails的新手,與Ransack有問題:
這是模型項目
class Project < ApplicationRecord
searchkick
belongs_to :company
belongs_to :m_category
has_many :project_industries, dependent: :destroy
has_many :m_industries, through: :project_industries
end
這是模特行業:
class Industry < ApplicationRecord
include M
belongs_to :m_industry_category
has_many :project_industries, dependent: :destroy, foreign_key: :industry_id
has_many :projects, through: :project_industries
end
這是模型IndustryCategory:
class IndustryCategory < ApplicationRecord
has_many :industries, dependent: :destroy,
foreign_key: :industry_category_id
has_many :projects, through: :industries
end
現在,我想通過IndustryCategory
搜索Project,但我不知道如何。 請幫我!! TKS
你可以使用這樣的東西
@industrty_category = IndustryCategory.find(params[:id])
@project = @industry_category.projects.all
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.