使用Devise

时间:2015-07-16 15:34:40

标签: ruby-on-rails ruby-on-rails-4 devise

我的rails 4应用程序中有一个“帐户”页面,我希望允许用户更新各种设置,包括他/她的密码。目前我正在使用Devise进行身份验证。我按照解决方案3下的instructions进行了自定义更新操作。我应该被定向到行动“accounts#update_password”,但我一直被重定向回“accounts #index”。我的设置如下所示。

# routes.rb
Rails.application.routes.draw do
  post '/accounts/update_password', to: 'accounts#update_password'
  get '/accounts', to: 'accounts#index'
end

# controllers/accounts_controller.rb
class AccountsController < ApplicationController
  def index
    # always gets here
  end
  def update_password
    # never gets here
  end
end

# views/accounts/index.html.erb
...
form_for(@customer, :url => {:action => "update_password"}, :html => { :method => :post, :role => 'form'} ) do |f| %>
...
<% end %>
...

HTML使用以下表单标题呈现,这对我来说是正确的。

<form role="form" class="edit_customer" id="edit_customer_1" action="/accounts/update_password" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" /><input type="hidden" name="authenticity_token" value="XXX==" />

但服务器日志显示以下请求。

GET /accounts?utf8=%E2%9C%93&authenticity_token=XXX&customer%5Bcurrent_password%5D=11111111&customer%5Bpassword%5D=11111111&customer%5Bpassword_confirmation%5D=11111111&commit=Reset HTTP/1.1

所以看来这个/ to / / update_password的POST被重写为来自/ accounts的GET。我唯一的猜测是有一些Devise魔法会导致重写,但我无法想象如何调试它。

以下是帐户页面的整个服务器日志,然后是密码更新:

desktop:~/rails$ bundle exec foreman start
12:05:22 web.1  | started with pid 27277
12:05:23 web.1  | Puma starting in single mode...
12:05:23 web.1  | * Version 2.11.3 (ruby 2.2.2-p95), codename: Intrepid Squirrel
12:05:23 web.1  | * Min threads: 0, max threads: 16
12:05:23 web.1  | * Environment: development
12:05:25 web.1  | * Listening on tcp://0.0.0.0:8081
12:05:25 web.1  | Use Ctrl-C to stop
12:05:28 web.1  | inside accounts#index
12:05:28 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:28 -0400] "GET /accounts HTTP/1.1" 200 - 0.5945
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap.min.self-a28237ec815e3256e572ee58558ef64d97fc965f398dbb27b4c49f0c3cc9e81c.css?body=1 HTTP/1.1" 304 - 0.0061
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /font-awesome.self-2d17540bab3759939e910ca38a695f014e0c777ded3ad7a01c4658b9d3fc980d.css?body=1 HTTP/1.1" 304 - 0.0105
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /application.self-167193cd81d9330d9ddb5c4ec7b44214fea529aa8a94f3a86e6526e4f652fc02.css?body=1 HTTP/1.1" 304 - 0.0121
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /admin.self-e5a326677fb0496249e2d9b207e088d8ade53b63199a9afc10e4d5c34a8fe852.css?body=1 HTTP/1.1" 304 - 0.0171
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /dashboard.self-a8a7602dfaa8429fc80356922713d926a873b01e816533dd35e7da4fd4f17b4f.css?body=1 HTTP/1.1" 304 - 0.0052
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /home.self-ef17fc5eca46c82c6b12e059a8fe09c95fbe5d83509f5076935e079e4dd1cb35.css?body=1 HTTP/1.1" 304 - 0.0062
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /main.self-915a7c6ba085c5ebc5049d24d148d1a4bdfc2796a1dccc6fa446265baef35feb.css?body=1 HTTP/1.1" 304 - 0.0090
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /pics.self-4fdd597579d18c7b2af45e9bba2490c4df39173c4cf2efc8b0378f5b7d8fa2a0.css?body=1 HTTP/1.1" 304 - 0.0103
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /jquery.self-d03a5518f45df77341bdbe6201ba3bfa547ebba8ed64f0ea56bfa5f96ea7c074.js?body=1 HTTP/1.1" 304 - 0.0101
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /jquery_ujs.self-8e98a7a072a6cee1372d19fff9ff3e6aa1e39a37d89d6f06861637d061113ee7.js?body=1 HTTP/1.1" 304 - 0.0043
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /turbolinks.self-c37727e9bd6b2735da5c311aa83fead54ed0be6cc8bd9a65309e9c5abe2cbfff.js?body=1 HTTP/1.1" 304 - 0.0036
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /main.self-5cfa1d5e9516170b67ca01262910f283bee073bfa58864b31a7268223072f72f.js?body=1 HTTP/1.1" 304 - 0.0035
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/affix.self-68d1a5161d04ca9fe1b9d9f4114d9426c7798bf90f2703a97aca35c8113469bb.js?body=1 HTTP/1.1" 304 - 0.0068
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/alert.self-15ce09eba576e56db3edfd87accc0ff48823df915169e350b4fd97290f96aee1.js?body=1 HTTP/1.1" 304 - 0.0110
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/button.self-37c62bff1d75f86f3348b8679873d5156d8b9938b62841038dca21690f4740f1.js?body=1 HTTP/1.1" 304 - 0.0099
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/carousel.self-9aaab1a477b9c1156bab751cb8da47f77dace6da88eef8ae830e60f3cff3a8be.js?body=1 HTTP/1.1" 304 - 0.0047
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/collapse.self-eeece00cd06a3d7cc071ab7845b549d4991edd0f0895e4be70fe40bac2fb5f4b.js?body=1 HTTP/1.1" 304 - 0.0045
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/dropdown.self-a3998e7ca949c04cb86b5c635deb0abcc7a24dc02e81be66b8acfef02d811e45.js?body=1 HTTP/1.1" 304 - 0.0047
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/modal.self-f2759e138605770e60526c00c6d86cbb3378da203641f9d6b204c9f0192b9267.js?body=1 HTTP/1.1" 304 - 0.0064
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/scrollspy.self-5ea180afe4404f83fc97d997833f2edefd34475b0b5ddab310e27abc2bbd5f2f.js?body=1 HTTP/1.1" 304 - 0.0052
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/tab.self-e1bba7115c90301056ee94c4716de2fcbe4498015def2dab9ff9879f339bd245.js?body=1 HTTP/1.1" 304 - 0.0049
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/transition.self-7742dca5e6acf313fbb217811b48468282cddf1a9baea5c89ec92e367ef242cb.js?body=1 HTTP/1.1" 304 - 0.0046
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/tooltip.self-c3b5c16f394ab9c0391db4431aac4f2d2ddf1bba4c5d3228ed343de05ecc8e83.js?body=1 HTTP/1.1" 304 - 0.0057
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap-sprockets.self-fbfa5ad7d9aa0afe439ec4ff3883acc4cb92b62cb67c40d674320c9aa1d4642d.js?body=1 HTTP/1.1" 304 - 0.0082
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /application.self-f98a0dd27ad1c55b2b9cfe97296d4887e5d4a4535b3bbbf9130c1050771738b2.js?body=1 HTTP/1.1" 304 - 0.0104
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /new_green_text-81b57c23c029666f646160a5a8259a3f1b19f232aa61298d117083890ea4653f.png HTTP/1.1" 304 - 0.0137
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /bootstrap/popover.self-2674d99c3ab0415dba0b958a80b3840f70ff6368b155d890306c0291be49453b.js?body=1 HTTP/1.1" 304 - 0.0166
12:05:29 web.1  | 192.168.0.100 - - [16/Jul/2015:12:05:29 -0400] "GET /favicon_blue-95baeb74af8071a4a6f5363edb0dd8c4c5b947cde77a70fdd4438c183b928296.ico HTTP/1.1" 200 1150 0.0040
12:08:51 web.1  | inside accounts#index
12:08:51 web.1  | 192.168.0.100 - - [16/Jul/2015:12:08:51 -0400] "GET /accounts?utf8=%E2%9C%93&_method=patch&authenticity_token=XXX%5Bcurrent_password%5D=11111111&customer%5Bpassword%5D=11111111&customer%5Bpassword_confirmation%5D=11111111&commit=Reset HTTP/1.1" 200 - 0.1868

0 个答案:

没有答案