现在我有这样的控制器方法:
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