Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Devise: "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.."

I have setup Devise on Rails 4.2.0 and everything seems to be working, I used the guide at:

http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/

My devise modules are:

devise :database_authenticatable, :registerable, :confirmable,
       :recoverable, :rememberable, :trackable, :validatable, :omniauthable

The only problem is that if I try to create a new account by going to the signup page, then after entering my email and new password (twice), I am taken back to the signin page and see the 'unauthenticated' message:

 You need to sign in or sign up before continuing

When instead I should get the 'send_instructions' message:

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

I have a before_filter in my ApplicationController:

before_filter :authenticate_user!, :except => [:show]

Though I confess that I don't understand why this doesn't give me authenticate errors on the signin page or the 'forgot password' page. Either way I tried adding :new_user_session to the :except, but that didn't help.

How can I get the right flash notice for when someone is signing up?

I have not overridden any of the devise code (other than what the sourcey doc suggests), my DeviseHelper only has a method for printing out the flash messages:

def devise_error_messages!
    return '' if resource.errors.empty?

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
    messages.html_safe
end

EDIT:

My initial search of SO didn't help (too many similar questions that weren't relevant) but now I've found this:

devise sign_in after sign_out error

So I believe the problem is that Devise is trying to take me to my root_path after I do the sign_up action. I don't know why it would do that for a :confirmable setup, it seems it should take me back to the sign_in page.

I tried to override this by overriding 'after_sign_up_path_for' in a cutom registrations controller using:

Override devise registrations controller

Perhaps I did it wrong, but that didn't seem to help.

So now the question is, how do I get Devise to go back to the sign_in page after someone does a sign_up, and why isn't this the default action for a confirmable setup?

like image 855
David Ljung Madison Stellar Avatar asked Apr 22 '15 20:04

David Ljung Madison Stellar


1 Answers

You mentioned overriding after_sign_up_path_for in a custom registrations controller, but following the the direction in this link, you might want to try placing that in your application_controller.rb.

like image 129
TerryCB Avatar answered Sep 30 '22 18:09

TerryCB