ROR:尝试使用 'put' 触发更新路由,但由于某种原因改为删除
ROR: Trying to trigger update route using 'put' but for some reason deleting instead
我有一个正在开发的 rails 应用程序,我正在使用 devise 进行身份验证。我遇到一个问题,当我尝试更新用户详细信息而不是向上更新用户时,用户刚刚被删除。
在 registrations/edit.html.erb 我有:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), method: :put) do |f| %>
... input tags and styling
<% end %>
生成 html:
<form class="edit_user" id="edit_user" enctype="multipart/form-data" action="/users" accept-charset="UTF-8" method="post">
<input type="hidden" name="_method" value="put" />
<input type="hidden" name="authenticity_token" value="Q2U4gEBfaIwCo2Vwi2fwXgwYLjzE4HpoDC8KN52m2GGqEdb94jd/c3TyFhEJtQEziHat9zFQs+e+fRJp4/j2WA==" />
... rest of the input tags
</form>
这里的关键是 rails 中的 <input type="hidden" name="_method" value="put" />
这应该会触发 PUT 路由,但由于某种原因,当我提交表单时它会触发删除路由:
Started DELETE "/users" for 127.0.0.1 at 2020-06-01 16:15:48 +0100
(0.6ms) SET NAMES utf8mb4 COLLATE utf8mb4_bin, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
(0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
有没有人以前遇到过这个问题并且知道是什么原因造成的?
编辑
我的config/routes.rb
# frozen_string_literal: true
Rails.application.routes.draw do
resources :posts
namespace :admin do
resources :users
root to: "users#index"
end
devise_for :users, module: 'users'
get 'profile', to: 'profile#index'
root to: "home#index"
end
我有一个正在开发的 rails 应用程序,我正在使用 devise 进行身份验证。我遇到一个问题,当我尝试更新用户详细信息而不是向上更新用户时,用户刚刚被删除。
在 registrations/edit.html.erb 我有:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), method: :put) do |f| %>
... input tags and styling
<% end %>
生成 html:
<form class="edit_user" id="edit_user" enctype="multipart/form-data" action="/users" accept-charset="UTF-8" method="post">
<input type="hidden" name="_method" value="put" />
<input type="hidden" name="authenticity_token" value="Q2U4gEBfaIwCo2Vwi2fwXgwYLjzE4HpoDC8KN52m2GGqEdb94jd/c3TyFhEJtQEziHat9zFQs+e+fRJp4/j2WA==" />
... rest of the input tags
</form>
这里的关键是 rails 中的 <input type="hidden" name="_method" value="put" />
这应该会触发 PUT 路由,但由于某种原因,当我提交表单时它会触发删除路由:
Started DELETE "/users" for 127.0.0.1 at 2020-06-01 16:15:48 +0100
(0.6ms) SET NAMES utf8mb4 COLLATE utf8mb4_bin, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
(0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
有没有人以前遇到过这个问题并且知道是什么原因造成的?
编辑
我的config/routes.rb
# frozen_string_literal: true
Rails.application.routes.draw do
resources :posts
namespace :admin do
resources :users
root to: "users#index"
end
devise_for :users, module: 'users'
get 'profile', to: 'profile#index'
root to: "home#index"
end