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? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 July 2011 21:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Jul 31, 2011 at 11:12 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 July 2011 21:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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) ... -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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Jul 31, 2011 at 1:47 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Jul 31, 2011 at 11:12 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On 30 July 2011 21:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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) ... > >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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 31 July 2011 22:52, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Jul 31, 2011 at 1:47 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> On Sun, Jul 31, 2011 at 11:12 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> On 30 July 2011 21:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 31 July 2011 22:52, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Sun, Jul 31, 2011 at 1:47 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >> > >> On Sun, Jul 31, 2011 at 11:12 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> > >>> On 30 July 2011 21:22, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > >>> To unsubscribe from this group, send email to > >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 August 2011 08:22, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote:> Add an accepts_nested_attributes_for call to Delivery for :delivery_items.done> Add a quantity attribute to DeliveryItemalready done> 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.But DeliveryItem belongs_to :product so to add, say three products, I have to create three delivery_items submitting the form three times. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Never used simple_form, but I''d try it like this. Forgive me if the syntax isn''t quite right. controller: def show @customer = Customer.find(params[:id]) @delivery = @customer.deliveries.build 3.times { @delivery.delivery_items.build } @products = Product.all @products_selected = [] Settings.default_delivery.products.each{|product| @products_selected << product.id_value} form: = simple_form_for @customer do |f| = f.simple_fields_for :deliver do |deliveries_f| = deliveries_f.input :notes = f.simple_fields_for :delivery_items do |delivery_items_f| = delivery_items_f.association :product, :multiple => false, :selected => @products_selected, :input_html => { :title => "- Select product -" }, :label => false = delivery_items_f.input :quantity Essentially, you''re using the same technique of building the DeliveryItems under the Delivery just as you built the Delivery under the Customer. With this technique, you''re limited to defining a fixed number of DeliveryItems before the form is produced, but adding a dynamic element that would add more rows if the user needs them should be trivial. HTH On Mon, Aug 1, 2011 at 10:41 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 1 August 2011 08:22, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote: > > > Add an accepts_nested_attributes_for call to Delivery for > :delivery_items. > > done > > > Add a quantity attribute to DeliveryItem > > already done > > > 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. > > But DeliveryItem belongs_to :product so to add, say three products, I > have to create three delivery_items submitting the form three times. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 August 2011 12:20, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote:> Never used simple_form, but I''d try it like this. Forgive me if the syntax > isn''t quite right. > controller: > > def show > > @customer = Customer.find(params[:id]) > @delivery = @customer.deliveries.build > > 3.times { @delivery.delivery_items.build }ùwhy 3.times? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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 reason. It can be whatever number of times you decide. If you want to show the user a form with 10 delivery items, then it would be 10.times. On Mon, Aug 1, 2011 at 1:30 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 1 August 2011 12:20, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote: > > Never used simple_form, but I''d try it like this. Forgive me if the > syntax > > isn''t quite right. > > controller: > > > > def show > > > > @customer = Customer.find(params[:id]) > > @delivery = @customer.deliveries.build > > > > 3.times { @delivery.delivery_items.build }ù > > why 3.times? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 1 August 2011 13:35, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote:> No reason. It can be whatever number of times you decide. If you want to > show the user a form with 10 delivery items, then it would be 10.times.That''s difficult because is the user that decide how much products deliver and then how much delivery_items contains a delivery. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Well then you need to go with an alternative that allows the user to add rows to the form using some dynamic HTML. I''d get it working with a static version as I''ve suggested first and then try to adapt it to this requirement. On Mon, Aug 1, 2011 at 1:43 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 1 August 2011 13:35, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote: > > No reason. It can be whatever number of times you decide. If you want > to > > show the user a form with 10 delivery items, then it would be 10.times. > > That''s difficult because is the user that decide how much products > deliver and then how much delivery_items contains a delivery. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Aug-01 13:20 UTC
Re: Re: setting an extra attribute of the join model.
On Aug 1, 2011, at 9:05 AM, Chris Kottom wrote:> Well then you need to go with an alternative that allows the user to > add rows to the form using some dynamic HTML. I''d get it working > with a static version as I''ve suggested first and then try to adapt > it to this requirement. > > On Mon, Aug 1, 2011 at 1:43 PM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > On 1 August 2011 13:35, Chris Kottom <chris-kMviOf/NVQxZWXO/OqhO/A@public.gmane.org> wrote: > > No reason. It can be whatever number of times you decide. If you > want to > > show the user a form with 10 delivery items, then it would be > 10.times. > > That''s difficult because is the user that decide how much products > deliver and then how much delivery_items contains a delivery.Work through the Railscast on accepts_nested_attributes (Complex Forms or something like that, don''t recall the title exactly -- it''s a two- parter) because Ryan covers this case exactly. And he follows the same path of "make it work as a static form first" that you should try to follow as a rule whenever making Ajax form magick happen. Walter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.