因此,当用户尝试更新其密码/头像/名称时,我遇到了问题。
问题在于设计模型注册。
在myapp/views/users/registrations/edit.html.erb
:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'form-horizontal' }) do |f| %> <%= devise_error_messages! %>
<div class="form-group">
<%= f.label :avatar, class: 'col-sm-2 control-label' %>
<div class="col-sm-6">
<%= f.file_field :avatar %>
</div>
</div>
<div class="form-group">
<%= f.label :name, class: 'col-sm-2 control-label'%>
<div class="col-sm-6">
<%= f.text_field :name, autofocus: true, class: 'form-control'%>
</div>
</div>
<div class="form-group">
<%= f.label :email, class: 'col-sm-2 control-label' %>
<div class="col-sm-6">
<%= f.email_field :email, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :password, class: 'col-sm-2 control-label' %> <i>(leave blank if you don't want to change it)</i>
<div class="col-sm-6">
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :password_confirmation, class: 'col-sm-2 control-label' %>
<div class="col-sm-6">
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :current_password, class: 'col-sm-2 control-label' %>
<i>(we need your current password to confirm your changes)</i>
<div class="col-sm-6">
<%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<%= f.submit "Update", class: "btn btn-primary" %>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
`Unhappy?`
<%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-default btn-xs' %>
<%= link_to "Back", :back %>
</div>
</div><% end %>
我的开发日志是
Started DELETE "/users" for 128.224.252.2 at 2017-06-21 17:21:26 +0000 Cannot render console from 128.224.252.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by Devise::RegistrationsController#destroy as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"RBkvQWXmVVY5rHEa7t0yh41QmMDS4HBcPCLJkKZ0RQYkpFfPXc7ebF6u3YKuF1BiOs5RDng3cFIWTFoZPmhLAw==", "user"=>{"name"=>"adnan", "email"=>"adhajar.work@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update"} User Load (2.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 104]] (0.2ms) BEGIN SQL (0.3ms) DELETE FROM "users_roles" WHERE "users_roles"."user_id" = $1 [["user_id", 104]] SQL (0.4ms) DELETE FROM "users" WHERE "users"."id" = $1 [["id", 104]] (3.0ms) COMMIT Redirected to https://confessionbox-adnanhajar.c9users.io/ Completed 302 Found in 47ms (ActiveRecord: 6.7ms)
Started GET "/" for 128.224.252.2 at 2017-06-21 17:21:26 +0000 Cannot render console from 128.224.252.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by PagesController#index as HTML Rendered pages/index.html.erb within layouts/application (68.0ms) Completed 200 OK in 74ms (Views: 72.8ms | ActiveRecord: 0.0ms)
Started GET "/users/sign_in" for 128.224.252.2 at 2017-06-21 17:43:01 +0000 Cannot render console from 128.224.252.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by Devise::SessionsController#new as HTML Rendered users/sessions/new.html.erb within layouts/application (81.2ms) Completed 200 OK in 90ms (Views: 87.9ms | ActiveRecord: 0.0ms)
Started GET "/users/auth/facebook" for 128.224.252.2 at 2017-06-21 17:43:03 +0000 Cannot render console from 128.224.252.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255`
知道为什么会这样吗?
先谢谢你了!