I have some code in my application layout view that requires an object to exist in order to work. The object exists on some controllers, but not all.
At first I thought I could use the after_filter on the application_controller to ensure that the object exists. But this didn’t work because the after_filter is only applied after the view is rendered and it is apparently an anti-pattern as well.
What is the best way to ensure that the object always exists, without unnecessarily creating the object on controllers that already create the object.
Say your variable is @foo.
application_helper.rb
then from any view, you just call your object by foo and not @foo.