I have a variable that I want to get in my application.html.erb application so that it is accessible to all views. I know that I can log in and add it to each controller and add it to each function so that it is available for indexing, display, etc. However, this is crazy. If I want it in the header, I must have access to it in the application.html.erb file so that it is in all of my views. An example of one of my controllers in which it works ...
def index if session[:car_info_id] @current_car_name = current_car.name end respond_to do |format| format.html
Here is my function in applicationcontroller:
private def current_car CarInfo.find(session[:car_info_id]) end
If I try to add @current_car_name = current_car.name to my application controller so that the variable is available for my .html.erb application, it will bomb with a Routing to current_car error. I know that the function works, because if I call it in another controller, it works fine, and I can access the variable created in this index view, or something else. You just need to know how to call the function once and have a variable available to all views, since it will be in my header. I could put the information in a session variable, but I read somewhere where you should restrict the session variables to identifiers and generate other necessary information from these identifiers.
Thanks in advance,
source share