【发布时间】:2015-01-08 07:58:55
【问题描述】:
我的模型中有一个范围 (scope :short_listed, -> ....)。要列出索引页面上的所有项目,我使用以下代码:
@posts = Post.cached_short_listed.paginate(:page => params[:page])
post.rb
def self.cached_short_listed
Rails.cache.fetch([name, "short_listed"], expires_in: 5.minutes) do
short_listed.to_a
end
end
我有这个错误
undefined method `paginate' for #<Array:
如果我删除 .paginate(:page => params[:page]) 和 <%= will_paginate....%> 一切正常。
如何使 will_paginate 与模型缓存一起使用。
【问题讨论】:
标签: ruby-on-rails caching