Redirect to original destination after login

Rails 2.3.11

If the user tries to go to / photos when they are not logged in, they are directed to [site]/admin/login?route=[site]/photos . After they log in, I would like them to be sent to everything that was defined in the "route" instead of the default home page.

In / app / controllers / admin _controller.rb:

 def login if session[:user_id] #already logged in redirect_to '' @destination = request.url end if request.post? if [authentication code] if user.activated? #check to see whether the user has activated their account session[:user_id] = user.id if params[:route] # ******** redirect_to "#{params[:route]}" else redirect_to :controller => 'home' end else flash.now[:notice] = "Your account hasn't been activated yet. Check your emails!" end else flash.now[:notice] = "Invalid email/password combination" end end end 

The string " * " is an incorrect operation. When I check to see the options: route is not one of them, so the argument is not passed with an entry entry. Can someone explain to me why this is not so and how can I fix it?

Thanks!

+6
source share
1 answer

You can do something like:

 session[:return_to] ||= request.referer 
+3
source

Source: https://habr.com/ru/post/893376/


All Articles