Monday, July 25, 2011

[Rails] 3 models in a form.

Hello,

class Customer < ActiveRecord::Base
has_many :deliveries

class Delivery < ActiveRecord::Base
has_many :delivery_items
has_many :products, :through => :delivery_items
belongs_to :customer

class DeliveryItem < ActiveRecord::Base
belongs_to :delivery
belongs_to :product

I create a new delivery for customer x:

= simple_form_for @customer do |f|
= f.simple_fields_for :deliveries do |deliveries_f|
.block
.column.span-12
= deliveries_f.association :products, :multiple => true,
:selected => @products_selected_id,
:input_html => { :title => "-
Select product -" }, :label => false
= deliveries_f.input :notes


DeliveryItem has the extra attribute quantity.
In this form I have to set a quantity DeliveryItem attribute so that I
create a Delivery for customer x, associate one or more Product and
for a product set the quantity.
How can I do in the form?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate