"The page you were looking for doesn't exist." 编辑表单

18 浏览
0 Comments

"The page you were looking for doesn't exist." 编辑表单

我有以下的route:

namespace :dashboard do
  get   '/courses/:id/edit'                     => 'courses#edit',                :as => :edit_course
  put   'courses/:id/update'                    => 'courses#update'
end

和这个form:

= form_tag dashboard_edit_course_url( @course), :method => 'post', :multipart => true do
  ...

这个form的action是:

但是当我提交这个form时,我得到了以下错误信息:

The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.

我不明白为什么会这样?有人能解释一下吗?

0
0 Comments

"The page you were looking for doesn't exist." 这个问题的出现原因是提交的表单中的第一个参数指定的页面不存在。在给定的链接中,指定了表单提交的目标页面的参数(update),但是该页面不存在。

解决方法是更改表单提交的目标页面的参数,确保指定的页面存在。根据链接中提供的文档,可以查看可用的参数选项,并选择一个存在的页面作为目标页面。

以下是解决方法的示例代码:

<%= form_tag({:action => "update", :controller => "pages"}, method: "post") do %>
  
<% end %>

在这个示例中,我们将表单提交的目标页面设置为 "update" 动作在 "pages" 控制器中。请根据实际情况修改参数,确保指定的页面存在。

0
0 Comments

在这个问题中,出现了"The page you were looking for doesn't exist."的错误提示。这个问题的原因是在表单中使用了post方法,但是没有配置post route。解决方法是将表单提交到update路径,使用put方法,因为这里是在更新记录。另外,建议使用path而不是url。然后,给更新路由命名为update route。根据使用的浏览器不同,可能不支持put方法,可以尝试使用post方法,尽管这不如put方法正确。

0
0 Comments

在处理此问题时,有一种替代方法。在您的路由中编写以下内容:

namespace :dashboard
  resources :courses, only: [:edit, :update]
end

然后在您的视图中编写以下内容:

= form_tag [:dashboard, ], multipart: true do |f| 

然后您将使用rails的默认设置。

更改路由可能需要重新启动rails服务器。否则,现在html中的表单是什么样子?

路由的改进很不错!

0