渲染部分视图导致错误
Rendering partial view resulting in error
rails 3.2
Ruby2.1.5
我正在尝试为票证制作一个表格,其中包括多个部分。
其中一个部分称为 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|
知道怎么做吗?
尝试更改渲染代码
= 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 }
如果使用 locals
,请务必记得添加 partial
。
使用这样的东西
= 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
rails 3.2 Ruby2.1.5
我正在尝试为票证制作一个表格,其中包括多个部分。
其中一个部分称为 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|
知道怎么做吗?
尝试更改渲染代码
= 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 }
如果使用 locals
,请务必记得添加 partial
。
使用这样的东西
= 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