I have the following code in my application helper.
route = ActionController::Routing::Routes.recognize_path(current_uri)
controller = route[:controller]
action = route[:action]
session['route']<< [controller.to_s,action.to_s]
I get the following error
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
Some quick logging and I see that controller and action work just fine. Can you not create sessions in helpers?
If you want the session to hold an array of these arrays (a “stack of routes” if you will), then you first need to make sure that
session[:route]is non-nil:Otherwise, simply assign it:
Also, you should use symbols as hash keys, not strings.