今、私はそのようなコントローラーメソッドを持っています:
def modelv
@model = Model.find(:all, :conditions => { :MOD_MFA_ID => params[:man]})
@ct = CountryDesignation.find(:all, :conditions => { :CDS_ID => "110000002"})
@destext = DesText.find(:all, :conditions => { :TEX_ID => "388555"})
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @model }
end
end
しかし、私はそれが次のように見えることを望みます:
def modelv
@model = Model.find(:all, :conditions => { :MOD_MFA_ID => params[:man]})
@ct = CountryDesignation.find(:all, :conditions => { :CDS_ID => @model.MOD_CDS_ID})
@destext = DesText.find(:all, :conditions => { :TEX_ID => @ct.CDS_TEX_ID})
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @model }
end
end
しかし、私のモデル構造は次のとおりです。
COUNTRY_DESIGNATIONS has_many モデル
DES_TEXTS has_many COUNTRY_DESIGNATIONS
メーカー has_many モデル
したがって、@model を選択した場合は配列、@ct を選択した場合は配列 (すべてのモデル)、@destext を選択した場合は配列です。これを正しく選択する方法。そして、これをどのように表示するのですか?今私のビューは次のようになります。
%p#notice= notice
%h3
- @model.each do |model|
%tr
%p
mod_id
%td= model.MOD_ID
name
-#%td= model.country_designations.des_texts.TEX_TEXT
= link_to 'Show model', model
= link_to 'Back', manufacturers_path
そして、私はこのように見えません:
%p#notice= notice
%h3
- @model.each do |model|
%tr
%p
mod_id
%td= model.MOD_ID
name
%td= @destext.TEX_TEXT
= link_to 'Show model', model
= link_to 'Back', manufacturers_path