0

I can have two types of users sign up on my app, "girls" and "boys". If a girl signs up I want to redirect to "/girls" and if a boy signs up I want to redirect to "/boys".

Is it possible to do custom redirection with Devise?

The closest docs I found are here: https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in. The problem is I can't do any check to switch the redirect route.

Options I've considered:

  1. Pass an additional URL param when user clicks "sign-up". like ?is_girl=1.
  2. After they click sign-up, when determining the redirect route, I could look at the users model and see if they're a girl or boy. Then redirect accordingly.
Don P
  • 60,113
  • 114
  • 300
  • 432
  • try to override create method for Devise::RegistrationsController - for example http://stackoverflow.com/questions/3546289/override-devise-registrations-controller (change redirect urls in action create directly) – Alexander Kobelev Jun 17 '14 at 20:50

1 Answers1

1

I am going to assume as part of the sign up process you ask them if they are a boy or girl and this is saved in the database.

So you would just need to do like the example in the Devise docs is showing

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    if resource.sex == 'boy'
      '/boy' # or you could create a route in routes.rb and do boy_path
    else
      '/girl' # with routes setup: girl_path
  end
end
CaptChrisD
  • 195
  • 5
  • Thanks CaptChrisD! I've been looking through the docs, do you know if there is a method where I can take an action in a controller 1 time after signup? I didn't see any method in the docs like `after_sign_in`. – Don P Jun 19 '14 at 00:20