我正在做一个rails应用程序,我使用的是 设计 来进行认证。我遇到了一个问题,当我试图更新用户的详细信息时,而不是更新用户,用户就被删除了。
在registrationsedit.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>
关键是... <input type="hidden" name="_method" value="put" />
在 rails 中,这应该触发 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
有人遇到过这种情况吗? 知道是什么原因吗?
编辑
我的configroutes.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