Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect Devise before_filter :authenticate_user to sign in path

Tags:

I'm using devise and have a quick question. How can I redirect the :authenticate_user! before_filter to the user sign up page instead of sign in? I've been going through https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb but haven't had much luck figuring out a solution.

like image 229
Glenn Avatar asked Dec 01 '11 04:12

Glenn


2 Answers

I had a similar issue where I needed to redirect to the signup if the user was not logged in. I fixed it by adding a method to the application_controller.rb and using it as a before filter in the other controllers.

Keep in mind that is is more of a temporary solution because it skips a bunch of devise´s abstractions.

  before_filter :auth_user    def auth_user     redirect_to new_user_registration_url unless user_signed_in?   end  
like image 137
Baconator507 Avatar answered Oct 23 '22 03:10

Baconator507


You're going to have to create a custom FailureApp that inherits from Devise's FailureApp as seen here: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

like image 41
Steve Avatar answered Oct 23 '22 02:10

Steve