I am trying to make clever caching of blog posts in order to reduce page load time, but it does not work: the cache is created once and is no longer updated.

# posts/show.html.slim #кэшировать пост как фрагмент с именем вида post-xxx. Если такого фрагмента в кэше нет, # то сервер отрисует его и закэширует, иначе -- загрузит из кэша. - cache "post-#{@post.id}" do = render @post = link_to 'Back', journal_path class ToolsController < ApplicationController def update case params[:type] when "post" @journal = @post.journal respond_to do |format| if @post.update(post_params) # При обновлении поста удаляем соответствующий ему фрагмент из кэша. # При следующем открытии поста кэш будет создан снова. expire_fragment('post-#{@post.id}') flash.notice = "Post successfully updated" format.html { render @post, notice: 'Post was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @post.errors, status: :unprocessable_entity } end end end end 

What am I doing wrong?

    1 answer 1

    Incorrect quotes when calling expire_fragment .

    And, if you have Rails version 4.0 or higher, then it suffices to write:

      - cache @post do 

    It will update itself when updating the model in @post.