Redirect user after log in only if it's on root_path

后端 未结 8 2316
傲寒
傲寒 2020-12-09 06:13

I have a root_path on my Rails application that is not user-protected i.e. it\'s a simple portal homepage, with a login form.

After the users log in, I\

8条回答
  •  佛祖请我去吃肉
    2020-12-09 06:23

    I think you're solution is more complex than necessary. Why don't you just do something simple like this on the action that the login form is posted to:

    def login
      // logic to check whether login credentials authorize user to sign in
      // say 'user_signed_in?' is boolean to determine whether user has successfully signed in
      redirect_to(user_signed_in? ? dashboard_path : root_path)
    end
    

提交回复
热议问题