0

I have this piece of code in view

<% cache("students_cache") do %>
  <% @swimming_students.each do |swimming_student| %>
    <tr class="gradeX">
      <td><%= link_to " #{swimming_student.full_name}", swimming_student %></td>
      <td><%= swimming_student.homephone %></td>          
    </tr>
  <% end %>
<% end %>

And I have the expire code in anther action

  def create
     expire_fragment("students_cache")
    @swimming_student = Swimming::Student.new(params[:swimming_student])

    respond_to do |format|
      if @swimming_student.save
        format.html { redirect_to @swimming_student, notice: 'Student was successfully created.' }
        format.json { render json: @swimming_student, status: :created, location: @swimming_student }
      else
        format.html { render action: "new" }
        format.json { render json: @swimming_student.errors, status: :unprocessable_entity }
      end
    end

end

But after I created a new student the cache was not updated.

Something is missing?

icn
  • 17,126
  • 39
  • 105
  • 141

1 Answers1

3

When using fragment caching with string keys, you should turn off cache digests:

<% cache("students_cache", skip_digest: true) do %>

See this Stackoverflow question for more details.

fivedigit
  • 18,464
  • 6
  • 54
  • 58