[英]How can I pass email of unconfirmed user to the session (Devise)?
我有一張注冊表,注冊后我希望瀏覽器記住用戶的電子郵件(仍未確認)。 我該怎么辦? 我以為我可以用某種方式做到這一點build_resource
的RegistrationsController
。
假設您想記住最后一個注冊/未確認的用戶,您可以這樣做:
在名為my_devise的應用程序/控制器下創建新文件夾
在app / controllser / my_devise中創建一個名為registrations_controller.rb的文件:
class MyDevise::RegistrationsController < Devise::RegistrationsController
# POST /resource
def create
build_resource
if resource.save
# here we save the registering user in a session variable
session[:registered_as] = resource
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
end
更新config / routes.rb文件,以告訴Devise使用我們的新控制器:
devise_for :users,
:controllers => {
:registrations => 'my_devise/registrations'
}
注冊后,會話變量:registered_as現在將保留最后一個注冊的用戶,並且可以在任何控制器或視圖中引用該用戶:
some_view.html.rb:
<p>Registered as:
<%= session[:registered_as].inspect %>
</p>
另請參閱: 覆蓋設計注冊控制器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.