问题描述
scope:current_budget,其中(:budget_review => Appconfig.budget_status)
方法budget_status本身被定义为
def self.budget_status
Appconfig.find_by_name('reviewed_budget')。value ==1? true:false
end
在本地测试时,如果我更改了reviewed_budget 参数,然后再次调用作用域,一切正常。
但是在Heroku上,即使我改变参数,它总是会给我相同的结果。
我试图在Heroku上显示Appconfig.budget_status的值,当它改变时我改变了设置。
尽管如此,named_scope似乎并没有这是考虑到的。
这里有一些缓存技巧吗?如果是这样的话,我该如何摆脱这种情况?
其他人,有没有人知道什么可能是错的?
谢谢,
p。
为了确保查询不被缓存可以使用以下语法来代替:
范围:CURRENT_BUDGET,λ-{其中(:budget_review => Appconfig.budget_status)}
lambda是什么在这种情况下有所作为。
I have a name scope that takes the result of a query as parameter:
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.
这篇关于在Heroku上缓存named_scope?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!