I use nested attributes, but fields are not loading in my view. Does anyone know what I am missing?
Rails 3.1, Ruby 1.9.2
Model 1:
class Traditions::Material < ActiveRecord::Base has_one :material_asset, :dependent => :destroy validates_presence_of :title accepts_nested_attributes_for :material_asset end
Model 2:
class Traditions::MaterialAsset < ActiveRecord::Base belongs_to :material has_attached_file :asset validates_attachment_presence :asset end
View (HAML):
= form_for @material, :html => {:class => 'form', :multipart => true} do |f| = errors_for @material .field = f.label :title = f.text_field :title .field = f.label :description = f.text_area :description, :rows => 5 .field = f.fields_for :material_asset do |ma| = ma.label :asset = ma.file_field :asset .buttonrow = f.submit 'Save'
HTML result (part):
<div class='field'></div> <div class='buttonrow'> <input name="commit" type="submit" value="Save" /> </div>
In the above, div.field empty.
source share