Reputation: 18220
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.
Upvotes: 0
Views: 99
Reputation: 7998
Hmmm, if I understand your question, I think you want to use a before_filter
. A before_filter
is a callback that is run before each action of any controller where the before_filter
is 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 from ActionController
.
class ApplicationController < ActionController::Base
before_filter :do_something
def do_something
WHATEVER IT IS YOU WANT TO DO INCLUDING SETTING INSTANCE VARIABLES
end
end
Then you can guarentee that do_something
will be called before any action.
Hope this helps.
Upvotes: 2