Accepts_nested_attributes_for and second-order associations, nested forms?

As far as you can't return order_id for order that isn't exist you can do this hook (I haven't test it, so you'll maybe need to fix it).

As far as you can't return order_id for order that isn't exist you can do this hook (I haven't test it, so you'll maybe need to fix it) def create customers = params:order. Delete :customers_attributes @order = Order. New params:order if @order.

Save customers. Each{|c| c:slips_attributes. Each{|s| s:order_id = @order.Id} } @order.

Customers_attributes = customers @order. Save end end def update @order = Order. Find params:id params:order:customers_attributes.

Each{|c| c:slips_attributes. Each{|s| s:order_id = @order.Id} } @order = Order. Update_attributes params:order @order.

Save end Also you'd better to remove all this logic into your model and you can dry it a little. This only about understanding an approach. UPD for your ID collisions.

It is only a scetch again def create customers = params:order. Delete :customers_attributes @order = Order. New params:order @order.

Customer_ids = customers.inject(){|a,h| a Save customers. Each{|c| c:slips_attributes. Each{|s| s:order_id = @order.Id} } @order.

Customers_attributes = customers @order. Save end end def update @order = Order. Find params:id @order.

Customer_ids = params:order:customers_attributes.inject(){|a,h| a Each{|s| s:order_id = @order. Id} } @order = Order. Update_attributes params:order @order.

Save end.

Perfect, that worked for me, although I had to change: customers. Each{|c| c:slips_attributes. Each{|s| s:order_id = @order.Id} } to customers.values.

Each{|c| c:slips_attributes.values. Each{|s| s:order_id = @order.Id} } – wdbmh Apr 11 at 18:52 not a big fix :D glad to help – fl00r Apr 11 at 18:56 Now clean your controllers and dry your methods. Remove all this stuff into model :) – fl00r Apr 11 at 18:56 Thx, yeah, I'll try.

Now I get another error: if I try to add an existing customer I get this message: ActiveRecord::RecordNotFound (Couldn't find Customer with ID=1 for Order with ID=7): – wdbmh Apr 12 at 7:55 what do you mean If I try to add an existing customer. You have got kind of a select field to choose customer or what? – fl00r Apr 12 at 9:20.

If I didn't mess up anything you could add has_many :slips, :through => :customers to Order model. And then use following structure in your view: I think it should work for @order. Save as well.

Edit: With this setup you don't actually need order_id in Slip model.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions