[英]Ransack: Search has_many through association
I am a newbie in Rails and have issues with Ransack: 我是Rails的新手,与Ransack有问题:
This is model Project 这是模型项目
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
This is model Industry: 这是模特行业:
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
And this is model IndustryCategory: 这是模型IndustryCategory:
class IndustryCategory < ApplicationRecord
has_many :industries, dependent: :destroy,
foreign_key: :industry_category_id
has_many :projects, through: :industries
end
Now, I want to search the Project by IndustryCategory
but I don't know how. 现在,我想通过
IndustryCategory
搜索Project,但我不知道如何。 please help me!! 请帮我!! tks
TKS
You can use something like this 你可以使用这样的东西
@industrty_category = IndustryCategory.find(params[:id])
@project = @industry_category.projects.all
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.