Ruby-on-rails – Redirect Devise before_filter :authenticate_user to sign in path

deviseruby-on-rails

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.

Best Answer

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

Related Topic