I've never really delved into the amazing cache techniques Rails provides until now. One thing that I really can't wrap my head around is how to resolve a this particular problem.
Given that I have a Blog model with many Posts:
class Blog < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
named_scope :published, :conditions => ["published_at < ?", Time.now]
end
And the show action in the BlogsController shows a list of Posts that have been published:
// BlogsController
def show
@blog = Blog.find(params[:id)
end
// View
<% @blog.posts.published.each do |p| %>
<h2><%=h p.title %></h2>
<%= simple_format(p.content) %>
<% end %>
The cache has to expire when any change is done to the published_at attribute BUT it also need to do it when published_at is put in the future and that time is reached.
Can you guys throw me some ideas and pointers of how to best solve this? Cron-job or am I loosing my mind?