我有一个非常奇怪的错误,我有一个设计用户模型
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :confirmable, :timeoutable,:omniauthable and
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
和我的routes.rb我有这些路线
devise_for :users, :controllers => {confirmations: 'confirmations', :registrations => "registrations", :sessions=>"sessions"}
我的更新用户表单看起来像这样
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<% if flash[:error] %>
<div class="alert alert-danger fade in" role="alert">
<%= flash[:error] %>
</div>
<% end %>
<% if devise_error_messages? %>
<div class="alert alert-danger fade in" role="alert">
<%= devise_error_messages! %>
</div>
<% end %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, autofocus: true,:class=>'custom-input form-control' %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="form-group">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i>
<%= f.password_field :password, autocomplete: "off", :class=>'custom-input form-control' %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: "off", :class=>'custom-input form-control' %>
</div>
<div class="form-group">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i>
<%= f.password_field :current_password, autocomplete: "off", :class=>'custom-input form-control' %>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-4">
<%= f.submit "Update", class: "btn btn-primary" %>
</div>
<div class="col-md-8">
<%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: "btn btn-danger" %>
</div>
</div>
</div>
<% end %>
当我尝试更新我的帐户时,它会破坏我的帐户而不是更新它我很震惊为什么我收到此错误请帮助我提前谢谢
答案 0 :(得分:7)
button_to
生成一个表单,因此您的标记将生成一个嵌套在第二个表单中的表单。
这不是合法的HTML,在过去我看到过一些表单中的提交按钮实际提交另一个表单的行为。这似乎是你正在发生的事情。
您应该将呼叫转移到表单
之外的button_to