2016-12-15 4 views
0

Ich bin ein Neuling in Rails und haben Probleme mit Ransack:Ransack: Suchen has_many durch Assoziation

Das ist Modellprojekt

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 

Dies ist Modell Industrie:

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 

Und das ist model IndustryCategory:

class IndustryCategory < ApplicationRecord 
    has_many :industries, dependent: :destroy, 
    foreign_key: :industry_category_id 

    has_many :projects, through: :industries 
end 

Nun möchte ich das Projekt von IndustryCategory suchen, aber ich weiß nicht wie. Bitte hilf mir!! tks

Antwort

0

Sie können so etwas wie dieses

@industrty_category = IndustryCategory.find(params[:id]) 

@project = @industry_category.projects.all 
+0

ich es nicht von Ransack :( –

+0

suchen denken verwende ich nicht bekommen, was Sie versuchen, Sie zu sagen, richtig bitte erklären. –

+0

ich habe Ihnen AR-Abfrage So können Sie Ransack entsprechend verwenden. –

Verwandte Themen