Ruby on Rails Sunday, July 31, 2011

I think your problem is in the way you've used the AR relationships in constructing the form you have there.  Your form is using the has-many-through relationship from Delivery to Product to construct the form.  This was all right before you had anything meaningful at the DeliveryItem level, but now the whole form needs to be reworked to stop thinking of Delivery as a bunch of Products and instead as a number of DeliveryItems, each of which is associated with a Product.

I haven't had to do anything like this before, but I would try to solve it as follows:
  1. Add an accepts_nested_attributes_for call to Delivery for :delivery_items.
  2. Add a quantity attribute to DeliveryItem 
  3. Change the form from a single select with a list of Products to a number of rows, each with a single-item select for Product and a text field for entering quantity.

On Mon, Aug 1, 2011 at 12:50 AM, Mauro <mrsanna1@gmail.com> wrote:
On 31 July 2011 22:52, Conrad Taylor <conradwt@gmail.com> wrote:
> On Sun, Jul 31, 2011 at 1:47 PM, Conrad Taylor <conradwt@gmail.com> wrote:
>>
>> On Sun, Jul 31, 2011 at 11:12 AM, Mauro <mrsanna1@gmail.com> wrote:
>>>
>>> On 30 July 2011 21:22, Mauro <mrsanna1@gmail.com> wrote:
>>> > https://gist.github.com/1114858.
>>> > How can I set the quantity DeliveryItem in the same form so that when
>>> > I update the customer attributes the Delivery is created with products
>>> > and their quantity?
>>> >
>>>
>>> no solution?
>>>
>>
>> Mauro, I'm not 100% sure what you're trying to ask here.  Thus, could you
>> explain
>> the steps starting with how the user would interact with the form to
>> what you would
>> like to happen?  For example,
>> a)  The user navigates to the page containing the form.
>> b)  The user does X
>> c)  ...

Ok, sorry but my english is really bad..........
Then, as you see in the code the Customer has many deliveries and one
Delivery has many products through delivery_items.
I want to do this: I call the show action for Customer;
I view customer details and a form to create a delivery for that customer.
The delivery has one or more products.
When I submit the form it creates the delivery for the customer with
one or more delivery_items, that is the join model.
The delivery_item contains the product but the quantity attribute is
nil, I want to populate the quantity when the delivery was created so
that the delivery has products with their quantity.
>
> Or do you have tests which might add some clarity to what you're trying to
> achieve?
>
>>
>> -Conrad
>>
>>>
>>> --
>>> 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.
>>>
>>
>
> --
> 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.
>

--
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.


--
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.

No comments:

Post a Comment