我是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
搜索项目,但我不知道如何。请帮我!! TKS
答案 0 :(得分:0)
你可以使用这样的东西
@industrty_category = IndustryCategory.find(params[:id])
@project = @industry_category.projects.all