【发布时间】:2020-06-01 15:38:50
【问题描述】:
我正在开发一个 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
以前有没有人遇到过这种情况并知道是什么原因造成的?
编辑
我的配置/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
【问题讨论】:
-
分享您的 routes.rb 文件或在控制台上点击“rake routes”命令并分享结果。
-
当然,已添加到帖子中:)
标签: ruby-on-rails ruby devise