Rails 3.2
我有一个视图/ tickets / show.html.slim视图,其中包含许多部分。我希望为每个部分配备不同的控制器,并执行New Save Edit
等操作所以在我的views / tickets / show.html.slim中,我有:
- @customer_info = customer_info @ticket
h4.form-header Customer Information
.form-section.attachments
- if @customer_info.nil?
= render partial: '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 :first
= f.text_field :first, maxlength: 50
.form-group
= f.label :last
= f.text_field :last, maxlength: 50
- logger.info("Marker 1")
.actions = link_to "Save", :controller => :customer_infos, :action => :create
- logger.info("Marker 2")
.clear
当我在测试模式下运行应用程序并选择票证时,我得到以下响应:
Incomplete response received from application
在我的test.log文件中,我有:
CustomerInfo加载(0.1ms)[0m SELECT customer_infos``.* FROM
customer_infos WHERE
customer_infos .
ticket_id` =' 1466026127'限制1
标记1
渲染的门票/部分/ _customer_info.html.slim(11.6ms)
在layouts / application(563.0ms)中呈现admin / tickets / show.html.slim
没有标记2
如果我更换:
.actions = link_to "Save", :controller => :customer_infos, :action => :create
使用:
.actions = f.submit 'Save'
然后表格呈现正常。
知道为什么这不起作用?
在我的门票/部分/ _customer_info.html.slim中,我做了:
.actions = link_to "Save", create_customer_info_path, method: :post
在我的routes.rb中,我有:
post '/customer_infos/create' => 'customer_infos#create', as: 'create_customer_info'
我现在收到以下错误消息:
undefined method `customer_infos_path' for #<#<Class:0x00000008bb54d8>:0x00000009df3c30>
customer_infos_path来自哪里?
如果我耙路线,我得到:
create_customer_info POST /customer_infos/create(.:format) customer_infos#create
答案 0 :(得分:1)
根据the Rails docs,使用controller
选项是不受欢迎的。您应该使用名称设置路线,如下所示:
post '/customers/create' => 'customer_infos#create', as: 'create_customer'
然后你的观点应该是这样的:
.actions
= link_to "Save", create_customer_path, method: :post
希望这有帮助!