index.html.haml
我必须在索引页面中显示客户详细信息列表。我想要嵌套的表单'商品地址'字段也将在索引页面中列出
%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

答案 0 :(得分:0)
可能是某些客户没有goods_address
,因此无法在each
对象上执行nil
尝试:
%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