注册在Devise for Rails中导致重定向循环

时间:2012-11-17 16:48:24

标签: ruby-on-rails devise ruby-on-rails-3.2 registration

使用Rails 3.2.9和Devise 2.1.2。当用户转到http://localhost:3000/users/sign_up时(对于替换为网址的localhost:3000生产相同),他们会注册。提交时,他们会反复重定向到/users/sign_up。 Chrome报告:

This webpage has a redirect loop
The webpage at http://localhost:3000/users/sign_up has resulted in too many redirects.

日志表示用户已创建且用户表也已更新以进行登录(实际上,如果我们转到另一个URL,则用户已在网站上创建并登录):

  ←[1m←[35mSQL (1.0ms)←[0m  INSERT INTO "users" ("created_at", "current_sign_in_at", "current_sign_in_ip", "em
ail", "encrypted_password", "first_name", "last_name", "last_sign_in_at", "last_sign_in_ip", "middle_name", "p
latform_id", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "update
d_at", "username") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["created_at", Sat, 17 Nov 201
2 08:39:33 PST -08:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "test@ucode.com"],
 ["encrypted_password", "$2a$10$NvmaFtw/JjILrkmkDNOi7ePj29qI3LRB2zTLAxsw6GRAW7PZekGme"], ["first_name", "Test"
], ["last_name", ""], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["middle_name", ""], ["platform_id",
 1], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_c
ount", 0], ["updated_at", Sat, 17 Nov 2012 08:39:33 PST -08:00], ["username", "test"]]
  ←[1m←[36m (4.0ms)←[0m  ←[1mcommit transaction←[0m
  ←[1m←[35m (0.0ms)←[0m  begin transaction
  ←[1m←[36m (1.0ms)←[0m  ←[1mUPDATE "users" SET "last_sign_in_at" = '2012-11-17 16:39:33.934552', "current_sig
n_in_at" = '2012-11-17 16:39:33.934552', "last_sign_in_ip" = '127.0.0.1', "current_sign_in_ip" = '127.0.0.1',
"sign_in_count" = 1, "updated_at" = '2012-11-17 16:39:33.953553' WHERE "users"."id" = 3←[0m
  ←[1m←[35m (4.0ms)←[0m  commit transaction

然后日志会报告重定向循环:

Redirected to http://localhost:3000/users/sign_up
Completed 302 Found in 178ms (ActiveRecord: 0.0ms)

Started GET "/users/sign_up" for 127.0.0.1 at 2012-11-17 08:39:33 -0800
Processing by Devise::RegistrationsController#new as HTML
  ←[1m←[36mUser Load (0.0ms)←[0m  ←[1mSELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1←[0m
Redirected to http://localhost:3000/users/sign_up
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.0ms)

Started GET "/users/sign_up" for 127.0.0.1 at 2012-11-17 08:39:34 -0800

这令人惊讶地似乎是默认行为,因为另一个新项目经历了完全相同的行为。我不应该指示人们/ users / sign_up注册吗?

与用户相关的rake routes输出:

     new_user_session GET    /users/sign_in(.:format)                            devise/sessions#new
         user_session POST   /users/sign_in(.:format)                            devise/sessions#create
 destroy_user_session DELETE /users/sign_out(.:format)                           devise/sessions#destroy
        user_password POST   /users/password(.:format)                           devise/passwords#create
    new_user_password GET    /users/password/new(.:format)                       devise/passwords#new
   edit_user_password GET    /users/password/edit(.:format)                      devise/passwords#edit
                      PUT    /users/password(.:format)                           devise/passwords#update

cancel_user_registration GET /users/cancel(.:format)设计/注册#uncod         user_registration POST /users(.:format)设计/注册#create     new_user_registration GET /users/sign_up(.:format)设计/注册#new    edit_user_registration GET /users/edit(.:format)设计/注册#edit                           PUT /users(.:format)设计/注册#update                           删除/users(.:format)设计/注册#stroy

0 个答案:

没有答案