Rails 3 - getting the last action / controller from the current controller

I need to be able to set my navigator on the current page, depending on which page the user was on.

eg

pageX => pageA (tab1selected) pageY => pageA (tab2selected)

I know that from reading you can use request.env ["HTTP_REFERER"], but I read that this does not always return if the user has a firewall, etc.

I use the application in my application if this helps.

Is there any other method?

Thanks Alex

0
source share
2 answers

Although this is not a quick fix, it works:

At the end of each controller with a view, call the method to configure your repository for the current action in the session. If you use multiple controllers, create another variable for the controller.

eg.

def index ... # your stuff set_action("index") end protected def set_action(action_name) session[:action]=action_name #session[:controller]="my_controller_name" end 

You can recreate the set_action method in each controller or create a helper, and then use 2 arguments:

 def last_visited(action_name, controller_name) session[:action]=action_name session[:controller]=controller_name end 
+2
source

This question was asked a long time ago, but for anyone else considering this, my solution (although a bit hacked):

 url = Rails.application.routes.recognize_path(request.referrer) last_controller = url[:controller] last_action = url[:action] 
+2
source

All Articles