Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法以编程方式刷新 Rails 中的范围?
我目前使用的范围如下:
scope :orphaned, lambda{where(prospects_count: 0)}
我希望缓存范围,但在添加或删除记录时以编程方式强制刷新。
我不确定是否有任何选项可以强制执行范围。如果您需要这种功能,请创建一个类似的方法
def orphaned orphaned = orphaned || self.where(:prospects_count => 0)) end
我认为这可以解决您的问题。
这是你想要的?
http://apidock.com/rails/ActiveRecord/Persistence/reload