2011-08-16 16 views
1

3モデルネストされた問題の属性 - クリップ

class Country < ActiveRecord::Base 
    has_many :regions 

    has_many :assets, :dependent => :destroy 
    accepts_nested_attributes_for :assets 
end 

class Region < ActiveRecord::Base 
    belongs_to :country 
    has_many :appartments 

    has_many :assets, :dependent => :destroy 
    accepts_nested_attributes_for :assets 
end 

class Asset < ActiveRecord::Base 
    belongs_to :region 
    belongs_to :country 
    has_attached_file :image, 
     :styles => { 
      :thumb=> "100x100>", 
      :small => "300x300>", 
      :large => "600x600>" 
      } 

end 

編集フォームを

<%= f.fields_for :assets do |asset| %> 

     <% if asset.object.new_record? %> 
      <%= asset.file_field :image %> 
     <% end %> 

    <% end %> 

マイ領域コントローラ:

def edit 
@country = Country.find(params[:country_id]) 


# For URL like /countries/1/regions/2/edit 

    @region = @country.regions.find(params[:id]) 
    5.times { @country.region.assets.build } 
end 

は私が

"undefined method `region' for #<Country:0x007fbf8b848198>" 
を取得

誰かアイデア?

+0

レムコでなければなりません。質問の書式設定を修正してください – fl00r

答えて

0
5.times { @country.region.assets.build } 

5.times { @region.assets.build } 
+0

はうまくいきません。データベース表の資産にcountry_id、image_filename、image_content、image_sizeは格納されていません。 region_idレコードはBD内にのみあります。 – Remco

+0

@ user874862 whta country? 'region_id'が必要です – fl00r

関連する問題