rails 3.2 Ruby 2.1.5
我正在尝试为故障单创建一个表单,其中包含许多部分。
其中一个sectios称为customer_info
在app / views / tickets / show.html.slim中,我有:
= render 'tickets/sections/customer_info', locals: { customer_info: CustomerInfo.new, ticket: @ticket }
在我的app / views / tickets / sections / _customer_info.html.slim中,我有:
= form_for customer_info do |f|
- f.hidden_field :ticket_id, :value => ticket.id
.form-horizontal-column.customer-info
.form-group
= f.label :pre_tax_total
= f.text_field :pre_tax_total, maxlength: 50
.form-group
= f.label :post_tax_total
= f.text_field :post_tax_total, maxlength: 50
.actions = f.submit 'Save'
.clear
当应用尝试呈现customer_info表单时,我收到以下错误消息:
undefined method `model_name' for NilClass:Class
当它到达表格中的第一行时:
= form_for customer_info do |f|
知道怎么做吗?
答案 0 :(得分:2)
尝试从
更改渲染代码= render 'tickets/sections/customer_info', locals: { customer_info: CustomerInfo.new, ticket: @ticket }
到
= render partial: 'tickets/sections/customer_info', locals: { customer_info: CustomerInfo.new, ticket: @ticket }
如果使用partial
,请务必添加locals
。
答案 1 :(得分:0)
使用类似的东西
= render 'tickets/sections/customer_info', locals: { ticket: @ticket }
和
= form_for CustomerInfo.new do |f|
- f.hidden_field :ticket_id, :value => ticket.id
.form-horizontal-column.customer-info
.form-group
= f.label :pre_tax_total
= f.text_field :pre_tax_total, maxlength: 50
.form-group
= f.label :post_tax_total
= f.text_field :post_tax_total, maxlength: 50
.actions = f.submit 'Save'
.clear