[英]“The page you were looking for doesn't exist.” edit form
I have the following route 我有以下路线
namespace :dashboard do
get '/courses/:id/edit' => 'courses#edit', :as => :edit_course
put 'courses/:id/update' => 'courses#update'
end
and this form 和这种形式
= form_tag dashboard_edit_course_url( @course), :method => 'post', :multipart => true do
...
the action being: 动作是:
<form accept-charset="UTF-8" action="http://localhost:3000/dashboard/courses/54633b9fc14ddd104c004de3/edit" enctype="multipart/form-data" method="post">
But when I submit the form I get this error: 但是当我提交表格时,我得到了这个错误:
The page you were looking for doesn't exist. 您要查找的页面不存在。
You may have mistyped the address or the page may have moved. 您可能输入了错误的地址,或者页面已经移动。
I don't understand why? 我不明白为什么? Could somebody explain? 有人可以解释吗?
An alternative way to handle this. 解决此问题的另一种方法。 In your routes write: 在您的路线中写:
namespace :dashboard
resources :courses, only: [:edit, :update]
end
And in your view write: 在您看来:
= form_tag [:dashboard, @course], multipart: true do |f|
Then you will use rails defaults. 然后,您将使用rails默认值。
Your form states to use post
, but you don't have a post route
configured. 您的表单声明要使用post
,但是您没有配置post route
。
The rails way to do this is to submit the form to the update path via put
, since you are updating a record : Rails的方法是通过put
将表单提交到更新路径,因为您正在更新记录 :
= form_tag dashboard_update_course_path( @course), :method => 'put', :multipart => true do
Also, you probably want to use path
instead of url
. 另外,您可能想使用path
而不是url
。
Then just name the update route
: 然后只需命名update route
:
namespace :dashboard do
get '/courses/:id/edit' => 'courses#edit', :as => :edit_course
put '/courses/:id/update' => 'courses#update', :as => :update_course
end
The first parameter is where the form submission should go (update). 第一个参数是提交表单的位置(更新)。
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.