简体   繁体   English

“您要查找的页面不存在。”编辑表单

[英]“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.

相关问题 无法在heroku上部署应用程序,总是得到“您要查找的页面不存在。”错误 - Can't deploy app on heroku, always get “The page you were looking for doesn't exist.” error 在商店上安装后的Heroku Shopify应用程序“您要查找的页面不存在。” - Heroku Shopify App after installation on shop “The page you were looking for doesn't exist.” Heroku Rails设置“您正在寻找的页面不存在。” - Heroku Rails Setup “The page you were looking for doesn't exist.” heroku“您要查找的页面不存在。”遵循Hartl的RoR指南 - heroku “The page you were looking for doesn't exist.” following Hartl's RoR guide Cloud9,GitHub和Heroku(您要查找的页面不存在。) - Cloud9, GitHub and Heroku (The page you were looking for doesn't exist.) rails heroku错误:未定义路线,但路线存在(您要查找的页面不存在。) - rails heroku error: no route defined, but route is there (The page you were looking for doesn't exist.) 您要查找的页面不存在 - The page you were looking for doesn't exist 您要查找的页面不存在。 您可能输入了错误的地址或页面已移动 - The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved 为什么当我在Heroku的另一个窗口中打开新链接时显示“您要查找的页面不存在”的原因。 - Why is it when I open a new link in another window on Heroku it says “The page you were looking for doesn't exist.” 使用devise gem在/ users / edit上部署后-“您要查找的页面不存在” - After deploying on /users/edit with devise gem — “The page you were looking for doesn't exist”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM