I have a registration form, and after registration I want browser to remember user's (still unconfirmed) email. How could I do that? I assume I can do this somehow with build_resource
of RegistrationsController
.
Asked
Active
Viewed 401 times
1

ciembor
- 7,189
- 13
- 59
- 100
-
What have you done yet and could be more specific on "I want browser to remember"? – ted Apr 08 '13 at 11:10
-
You can access user obj you're creating with `@user = build_resource` in your devise overwritten controller if that's what you're asking. – Vadym Chumel Apr 08 '13 at 11:27
1 Answers
0
Assuming you want to remember the last registered/un-confirmed user you could do this:
Create new folder under app/controllers called my_devise
Create a file called registrations_controller.rb in app/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
Update the config/routes.rb file to tell Devise to use our new controller:
devise_for :users,
:controllers => {
:registrations => 'my_devise/registrations'
}
After registration, the session variable :registered_as will now hold the last user that registered and could be referenced in any controller or view:
some_view.html.rb:
<p>Registered as:
<%= session[:registered_as].inspect %>
</p>
See also: Override devise registrations controller

Community
- 1
- 1

RidingTheRails
- 1,105
- 1
- 12
- 22