Hari Prakash Hari Prakash - 4 months ago 19
Ruby Question

rails Cannot nest nested form with parent form in index page

index.html.haml

I have to display customer detail list in index page.I want the nested form 'goods address' fields also to be listed in index page



%tbody
- @customer_details.each do |customer|
%tr
%td= customer.customer_name
%td= customer.customer_id
%td= customer.address
%td= customer.state
%td= customer.email
- customer.goods_address.each do |goods_address|
%td= goods_address.delivery_address
%td= goods_address.name
%td= goods_address.address
%td= goods_address.state




The problem is im getting undefined method 'each' for goods address. I dont know how to solve this. can someone help me.Thanks in advance

Answer

may be some of customer does not have goods_address so each can not performed on nil obect

Try:

%tbody
  - @customer_details.each do |customer|
    %tr
      %td= customer.customer_name
      %td= customer.customer_id
      %td= customer.address
      %td= customer.state
      %td= customer.email
        - if customer.goods_address.present?
          %td= customer.goods_address.delivery_address
          %td= customer.goods_address.name
          %td= customer.goods_address.address
          %td= customer.goods_address.state