I want to render a view with the action being executed as well. Basically I have a number of “upcoming bookings” that need to display on every single page. It’s a quick look at what’s coming up so the user can get an overall view of what’s going on.
What I had planned on doing is having a caching mechanism for that specific action, so then when I rendered it, most likely in the layout, then it would be fast.
Is this possible? It seems render template and render partial don’t call the action which means the instance variables accessible in that view aren’t available, or they simply don’t do what I want.
Hmmm, if I understand your question, I think you want to use a
before_filter. Abefore_filteris a callback that is run before each action of any controller where thebefore_filteris registered or in any of its descendants.If you really want a function called before any action of any controller, then the way that I recommend doing this is in the
ApplicationController, then it will be executed for any action on any controller that inherits fromActionController.Then you can guarentee that
do_somethingwill be called before any action.Hope this helps.