2013-04-08 33 views
1

我有一个注册表单,注册后我希望浏览器记住用户的(尚未确认的)电子邮件。我怎么能这样做?我想我可以用build_resourceRegistrationsController做点什么。如何将未经确认的用户的电子邮件传递给会话(Devise)?

+0

你还做了什么,可以更具体的“我想要浏览器记住”? – ted 2013-04-08 11:10:17

+0

如果这就是你要求的,你可以在你的设计被覆盖的控制器中用'@user = build_resource'来访问你正在创建的用户obj。 – 2013-04-08 11:27:20

回答

0

假设你要记住,你可以这样做最后的注册/未确认的用户:

下的应用程序创建新的文件夹/控制器称为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> 

参见:Override devise registrations controller

相关问题