I have two models - Post and Comment. I'm using fragment caching to cache each post
like so:
- @posts.each do |post|
- cache post do
= render 'posts/post', post: post
post.rb
class Post < ActiveRecord::Base
belongs_to :user, touch: true
has_many :comments, dependent: :destroy
end
Now my comments.rb
file is as follows:
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :post, touch: true
end
This works as expected. Whenever I add a new comment to a post, the cache key of that particular post expires. However, when I delete a comment from a post, the cache key of that post doesn't expire. What gives?