1
我有一個註冊表單,註冊後我希望瀏覽器記住用戶的(尚未確認的)電子郵件。我怎麼能這樣做?我想我可以用build_resource
的RegistrationsController
做點什麼。如何將未經確認的用戶的電子郵件傳遞給會話(Devise)?
我有一個註冊表單,註冊後我希望瀏覽器記住用戶的(尚未確認的)電子郵件。我怎麼能這樣做?我想我可以用build_resource
的RegistrationsController
做點什麼。如何將未經確認的用戶的電子郵件傳遞給會話(Devise)?
假設你要記住,你可以這樣做最後的註冊/未確認的用戶:
下的應用程序創建新的文件夾/控制器稱爲my_devise
創建一個名爲registrations_controller.rb文件在應用程序/ controllser/my_devise:
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_for :users,
:controllers => {
:registrations => 'my_devise/registrations'
}
註冊後,會話變量:registered_as現在認爲註冊並可以在任何控制器引用或最後一個用戶視圖:
some_view.html.rb:
<p>Registered as:
<%= session[:registered_as].inspect %>
</p>
你還做了什麼,可以更具體的「我想要瀏覽器記住」? – ted 2013-04-08 11:10:17
如果這就是你要求的,你可以在你的設計被覆蓋的控制器中用'@user = build_resource'來訪問你正在創建的用戶obj。 – 2013-04-08 11:27:20