Cached named_scope on Heroku?
I have a name scope that takes the result of a query as pa开发者_StackOverflow中文版rameter:
scope :current_budget, where(:budget_review => Appconfig.budget_status)
Method budget_status is itself defined as
def self.budget_status
Appconfig.find_by_name('reviewed_budget').value=="1" ? true : false
end
When testing locally, if I changed the value of the "reviewed_budget" parameter and then call the scope again, everything works fine.
But on Heroku, it will always give me the same result, even if I change the parameter. I tried to display the value of Appconfig.budget_status on Heroku and it changes when I change my setting.
Still, the named_scope doesn't seem to take this into account.
Is there some caching trick here? if so how do I get rid of this for this specific situation? Else, does anyone have an idea of what could be wrong?
thanks, p.
When you test locally, I assume you run a development environment which will reload all your code every time it is called and will because of that avoid this problem. In production (Heroku) however it will cache, not the result but the query, of the scope if used like you do currently.
To make sure the query is not cached you can use the following syntax instead:
scope :current_budget, lambda { where(:budget_review => Appconfig.budget_status) }
lambda is what makes a difference in this case.
精彩评论