Topic: Problems in Nested Form.

Hi All,

I'm a newbie in ruby on rails programming.

anybody can help for below issue ?

* Model PurchaseOrder with has_many relationship to PurchaseOrderDetail.
* i have a PurchaseOrder view that Contain PO Header and list of PO detail
* i have a JQuery UI dialog to add into List Of Po Detail.


the scenario is can i add purchase order detail and store temporary (Which means i can remove or edit or add another detail)
before save purchase order ?

After add PO Detail in Dialog Form , it will show in my PO List. (Something same like Add To Cart in most ecommerce website).

So When i call @PurchaseOrder.save(), activeRecord begin to create Po and it detail.

May i know can ruby on rails support on that ?
And How To do it ?


Hope all senior can help about that. smile

Thanks before and best Regards,

Last edited by AryantoNg (2012-08-14 06:23:53)

Re: Problems in Nested Form.

Yes, see:
http://railscasts.com/episodes/196-nest … orm-part-1
http://rubysource.com/complex-rails-for … ttributes/

Please remember to add to PurchaseOrder model:

attr_accessible :purchase_order_detail_attributes

Re: Problems in Nested Form.

Hi.. Thanks a lot for your reference.

by the way.. may i know from index view can i access child attributes from parent ? (Has_one relationship)
Here is my code :
<% @purchase_orders.each do |po|%>     
      <tr id="<%= dom_id po%>">
             <td><%= po.code %></td>
             <td><%= po.purchase_order_detail.description if po.purchase_order_detail %></td>
........

as i know we can access parent attr from child object.
but i don't know can we access child attr from parent object ?

Thanks before for your guide


Best Regards,

Last edited by AryantoNg (2012-08-15 03:19:11)