Redirect after registration

580 views
Skip to first unread message

Neil

unread,
Jun 1, 2010, 8:04:02 AM6/1/10
to Devise
I have an application where the requirement is that once a user has
filled in the registration form, that they are signed in, and taken to
a page thanking them for the registration.

How would I go about doing this with Devise? I am not using
confirmation emails.

Christopher Your / Ignition Industries

unread,
Jun 1, 2010, 11:31:23 AM6/1/10
to plataforma...@googlegroups.com
You will find answers to most or your Devise questions here:
http://rdoc.info/projects/plataformatec/devise

Scroll down to Configuring controllers. Essentially, you will want to create
a controller that extends Devise's RegistrationsController like this:

class Users::RegistrationsController < Devise::RegistrationsController
def after_sign_in_path_for(resource)
user_thank_you_path
end
End

What you're doing is overwriting the after_sign_in_path for the
RegistrationsController.

Make sure to copy the Devise views from devise/registrations/edit.html.erb
and devise/registrations/new.html.erb to users/registrations/edit.html.erb
and users/registrations/new.html.erb

You will also want to do something like this in your routes:

devise_for :users, :controllers => { :registrations => "users/sessions" }

Hope that helps you out.

Chris Your

Neil

unread,
Jun 2, 2010, 9:43:53 AM6/2/10
to Devise
How would I acheive the same thing, but being able to redirect to some
sort of saved location?

i.e Registration process a ends at page x
Registration process b ends at page Y

N

On Jun 1, 4:31 pm, Christopher Your / Ignition Industries
<christophery...@gmail.com> wrote:
> You will find answers to most or your Devise questions here:http://rdoc.info/projects/plataformatec/devise
>
> Scroll down to Configuring controllers. Essentially, you will want to create
> a controller that extends Devise's RegistrationsController like this:
>
> class Users::RegistrationsController < Devise::RegistrationsController
>   def after_sign_in_path_for(resource)
>     user_thank_you_path
>   end
> End
>
> What you're doing is overwriting the after_sign_in_path for the
> RegistrationsController.
>
> Make sure to copy the Devise views from devise/registrations/edit.html.erb
> and devise/registrations/new.html.erb to users/registrations/edit.html.erb
> and users/registrations/new.html.erb
>
> You will also want to do something like this in your routes:
>
> devise_for :users, :controllers => { :registrations => "users/sessions" }
>
> Hope that helps you out.
>
> Chris Your
>

Christopher Your / Ignition Industries

unread,
Jun 2, 2010, 11:54:10 AM6/2/10
to plataforma...@googlegroups.com
You're going to have to overwrite the create method in
Users::RegistrationsController (which extends from
Devise::RegistrationsController) and pass in some params through your form.
You could name it after_sign_up_path. Something like:

def create
build_resource

if resource.save
set_flash_message :notice, :signed_up
sign_in(resource_name, resource)
redirect_to params[:after_sign_up_path] ||
after_sign_in_path_for(resource)
else
clean_up_passwords(resource)
render_with_scope :new
end
end

That should get you started... unless José has a better idea.

Chris Your

Walter Davis

unread,
Jun 2, 2010, 12:53:14 PM6/2/10
to plataforma...@googlegroups.com
Have you looked at this page?

http://wiki.github.com/plataformatec/devise/howto-redirect-to-a-specific-page-on-successful-sign-in

Walter

On Jun 2, 2010, at 11:54 AM, Christopher Your / Ignition Industries
wrote:

Walter Davis

unread,
Jun 2, 2010, 12:55:39 PM6/2/10
to plataforma...@googlegroups.com
There's also this hack, which I can't recall where I saw (probably
from someone else on this list):

###ApplicationController
def stored_location_for( resource )
if current_user
Rails.logger.info "count: " + current_user.sign_in_count.to_s
if current_user.sign_in_count <= 1
UserMailer.deliver_first_visit(current_user)
elsif ( current_user.first_name.blank? ||
current_user.last_name.blank? || current_user.phone.blank? ||
current_user.company_name.blank? )
set_flash_message :notice, 'Please update your profile'
return '/users/' + current_user.id.to_s + '/edit'
end
end
super( resource )
end

Not pretty, but it works for what I need to do.

Walter

On Jun 2, 2010, at 11:54 AM, Christopher Your / Ignition Industries
wrote:

>>> Make sure to copy the Devise views from devise/registrations/
>>> edit.html.erb
>>> and devise/registrations/new.html.erb to users/registrations/
>>> edit.html.erb

Reply all
Reply to author
Forward
0 new messages