http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
Haven't tested it, but perhaps you try something like this: class Customer has_many :deliveries has_one :document accepts_nested_attributes_for :deliveries, :reject_if => lamda { |attributes| attributes['delivered_at'].blank?} accepts_nested_attributes_for :document ... end <%= form_for(@customer) do |f| %> <%= f.fields_for :deliveries, @delivery do |delivery_fields %> <%= delivery_fields.input :delivered_at, :as => :hidden, :value => Date.today %> <% end %> <%= f.fields_for :document do |doc_fields| %> <%= doc_fields.label :doc_type %> <%= doc_fields.text_field :doc_type %> <%= doc_fields.error :doc_type %> <% end %> <%= f.submit %> <% end %> On 03/02/11 17:52, Mauro wrote:
I have: Customer has_many :deliveries has_one :document Document belongs_to :customer Delivery belongs_to :customer route.rb has: resources :customers do resources :deliveries end I already have customers in the database, I only have to add deliveries and document to one customer. I want to do with one single form. Obviously this one doesn't work: <%= form_for([@customer, @delivery]) do |f| %> <%= f.input :delivered_at, :as => :hidden, :value => Date.today %> <%= f.fields_for :document do |doc| %> <%= doc.label :doc_type %> <%= doc.text_field :doc_type %> <%= doc.error :doc_type %> <% end %> <%= f.submit %> It adds deliveries but not document. Some advices?
-- best regards Bente Pieck -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.