Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect to registration page if user not signed-in in devise

From reading the devise code and wiki it seems, there is no option to redirect user to registration page if a user is not logged in. In lib/devise/failure_app.rb, it appear that the redirect url is hardcoded.

  def redirect_url
    opts  = {}
    route = :"new_#{scope}_session_path"
    opts[:format] = request_format unless skip_format?

    if respond_to?(route)
      send(route, opts)
    else
      root_path(opts)
    end
  end

I want to ask that's the best practice in getting the work done. I'm thinking of manually setting user_return_to session value, then make a call to registration page. Is that a good practice?

like image 976
Clark Avatar asked Nov 04 '11 06:11

Clark


1 Answers

I think the best practice in this situation is following this devise wiki page: https://github.com/plataformatec/devise/wiki/How-To%3A-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

like image 101
Ireneusz Skrobis Avatar answered Nov 15 '22 05:11

Ireneusz Skrobis