我逐字遵循本教程:
https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up
但是当用户单击确认链接时,它不会显示他们设置密码的屏幕,但会将它们设置为已确认。我查看了日志,它向确认控制器发出请求,但不显示视图 - 只是处理令牌并重定向到登录的根。
Started GET "/users/confirmation?confirmation_token=gs5NCZTu3hSJeWqCGDr6" for 127.0.0.1 at 2013-08-18 00:15:06 +0100
Processing by Devise::ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"gs5NCZTu3hSJeWqCGDr6"}
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'gs5NCZTu3hSJeWqCGDr6' LIMIT 1[0m
[1m[35m (0.1ms)[0m BEGIN
[1m[36m (0.5ms)[0m [1mUPDATE "users" SET "confirmation_token" = NULL, "confirmed_at" = '2013-08-17 23:15:06.840455', "updated_at" = '2013-08-17 23:15:06.841240' WHERE "users"."id" = 4[0m
[1m[35m (0.4ms)[0m COMMIT
[1m[36m (0.1ms)[0m [1mBEGIN[0m
[1m[35m (0.3ms)[0m UPDATE "users" SET "last_sign_in_at" = '2013-08-17 23:15:06.843987', "current_sign_in_at" = '2013-08-17 23:15:06.843987', "last_sign_in_ip" = '127.0.0.1', "current_sign_in_ip" = '127.0.0.1', "sign_in_count" = 1, "updated_at" = '2013-08-17 23:15:06.844495' WHERE "users"."id" = 4
[1m[36m (0.3ms)[0m [1mCOMMIT[0m
Redirected to http://0.0.0.0:5000/
我的路线(按照指示)是:
devise_for :users, :controllers => { :registrations => "registrations", :confirmations => 'confirmations' }
devise_scope :user do
put "/confirm" => "confirmations#confirm"
end
我在 app/views/devise/confirmations 和 app/views/confirmations 中有一个 show.html.erb,以防万一他们的说明(误导性地)这样说。
我认为这可能与您制作的这个控制器有关:
class ConfirmationsController < Devise::ConfirmationsController
def show
self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) if params[:confirmation_token].present?
super if resource.nil? or resource.confirmed?
end
它应该在这里渲染视图吗?因为 this 的超类从不调用 show :
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource) if Devise.allow_insecure_sign_in_after_confirmation
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
end
end
编辑:我已将确认控制器中的代码更改为纯粹render :action => "show"
以确保它正在使用我的控制器,但它没有任何效果。我仔细检查了一下rake routes
,它似乎是正确的,但似乎并没有压倒一切:
POST /users/confirmation(.:format) confirmations#create
GET /users/confirmation/new(.:format) confirmations#new
GET /users/confirmation(.:format) confirmations#show
confirmation PUT /confirmation(.:format) confirmations#confirm