Simple Form post 表单到不同的控制器和动作
SimpleForm post form to differnt controller and action
我有活动展示页面,我在其中显示 @customer
的客户表格。如果事件是不同类型的事件,那么我会显示一个用于@registration 的表单,我想 post 该表单到 RegistrationsController#create.
现在在我的路线中我有这个:
路线
post '/:slug' => 'events#create', as: :registration
表格
<%= simple_form_for @registration, url: custom_registration_path, html: { class: 'form, styled-form', autocomplete: 'off' } do |f| %>
...
<% end %>
上面的表格仍然 post 到 EventsController#create
我在 EventsController#show
中定义了@registration,我想 post 将表单 custom_registration_path。
如何定义路线?我仍然想将 :slug
发送到 RegistrationsController。
如果我理解正确的话:
不能有两个具有相同 HTTP 方法和路径的路由。 method + path
组合必须是唯一的。
您要么应该将自定义注册路由到 custom_registrations/:slug
之类的路径,要么更改 events#create
的路径
当然,您可以针对不同的操作使用不同的方法。 PUT
例如。但我认为这是一种不好的做法,因为它非常隐含,对于使用此代码的任何人来说都很难理解。
我有活动展示页面,我在其中显示 @customer
的客户表格。如果事件是不同类型的事件,那么我会显示一个用于@registration 的表单,我想 post 该表单到 RegistrationsController#create.
现在在我的路线中我有这个:
路线
post '/:slug' => 'events#create', as: :registration
表格
<%= simple_form_for @registration, url: custom_registration_path, html: { class: 'form, styled-form', autocomplete: 'off' } do |f| %>
...
<% end %>
上面的表格仍然 post 到 EventsController#create
我在 EventsController#show
中定义了@registration,我想 post 将表单 custom_registration_path。
如何定义路线?我仍然想将 :slug
发送到 RegistrationsController。
如果我理解正确的话:
不能有两个具有相同 HTTP 方法和路径的路由。 method + path
组合必须是唯一的。
您要么应该将自定义注册路由到 custom_registrations/:slug
之类的路径,要么更改 events#create
当然,您可以针对不同的操作使用不同的方法。 PUT
例如。但我认为这是一种不好的做法,因为它非常隐含,对于使用此代码的任何人来说都很难理解。