Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devise: adding notice after sign up (with confirmable)

I added :confirmable to my Rails app subsequently. The problem is that when I sign up after adding :confirmable I don't get a notice displayed after the sign up for with telling me what happened, for instance:

You will receive an email with instructions about how to confirm your account in a few minutes.

Why doesn't notice appear and how can I add that notice after adding :confirmable?

Thanks for help

like image 438
all jazz Avatar asked Sep 23 '13 21:09

all jazz


1 Answers

Notice does not appear because the devise is redirecting to your root path which is probably protected by devise authentication. When you hit root_path, you get redirected back to sign_in page (because devise couldnt sign-in the user since it is not activated yet). You can verify that by looking on your development log after you enter user information and hit "sign-up" button - you will see in the log one request for registering a user, then a request navigating to your root url (whatever is in your routes.rb) and then redirect navigation to sign_in page because of authentication.

During redirect all flash messages are lost (since flash messages are only valid for next request only) and when you get redirected from root_path to sign_in page, you are making to requests. So you either need to use flash.keep on the first request before it gets redirected, or change the after_sign_up path so redirection does not happen. I recommend changing after_sign_up path since it's easier and looks as a right way to go about it.

To do that, you need to use your own controller for registrations and add after_sign_up_path method that returns url for redirect:

# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController

  private

  def after_inactive_sign_up_path_for(resource)
    new_user_session_path
  end
end

#config/routes.rb
devise_for :users, :controllers => { :registrations => "registrations" }

I also recommend reading similar question to yours: Rails 3 and Devise: Redirecting to page following signup (confirmable)

like image 73
Iuri G. Avatar answered Nov 07 '22 05:11

Iuri G.