0

I have a Rails 4.0.0 application running in development mode, served via passenger 4.0.8 and apache2. Our clients run IE 8, and I cannot change that fact.

I'm experiencing issues with caching, in which I create a new record, but the new record does not display when the index is called. I can immediately see the new record in the database, but the record does not display on the index page. I can hit refresh several times, and it eventually shows up. Rebooting the web server does not necessarily fix the issue, nor does clearing IE cache or closing the browser altogether.

The weird thing is that sometimes if I hit refresh a few times, it displays older versions of the page, sometimes as far as 3 versions back. Then, if I hit refresh again, the record could be gone altogether or show the correct, newest version. It's arbitrary.

There are no errors in my log files.

I'm not sure what information you need to further troubleshoot, but I can post whatever you need or show you my git repo.

I'm running other Rails 4.0.0 applications on this same server and have not experienced this issue before (though, maybe I'm just now noticing it).

Can anyone point me in the right direction? Thanks in advance.

EDIT - development.rb

Serta::Application.configure do

  config.cache_classes = false      
  config.eager_load = false    
  config.consider_all_requests_local       = true      
  config.action_controller.perform_caching = false    
  config.action_mailer.raise_delivery_errors = false    
  config.active_support.deprecation = :log    
  config.active_record.migration_error = :page_load    
  config.assets.debug = true      
  Paperclip.options[:command_path] = "/usr/local/bin/"

end

Nothing cache-related in application.rb. Just timezone stuff.

EDIT 2 - model, controller and view:

All of my models are doing the same thing, here's a sample mvc:

class Location < ActiveRecord::Base

  has_many :incidents
  belongs_to :location_group

  validates :name, :location_group_id, :presence => true
  validates :name, :uniqueness => true

  scope :sorted, order("name ASC")

  def self.active
    where(active: true)
  end

end

locations_controller:

class LocationsController < ApplicationController
  before_action :set_location, only: [:show, :edit, :update, :destroy]

  def index
    @locations = Location.sorted 
  end

  def create
    @location = Location.new(location_params)
    respond_to do |format|
      if @location.save
        format.html { redirect_to locations_path, notice: 'Location was successfully created.' }
        format.json { render action: 'show', status: :created, location: @location }
      else
        format.html { render action: 'new' }
        format.json { render json: @location.errors, status: :unprocessable_entity }
      end
    end
  end

  private

    def set_location
      @location = Location.find(params[:id])
    end

    def location_params
      params.require(:location).permit(:name, :address, :location_group_id, :active)
    end
end

index.html.erb:

<% @title = "Locations" %>

<div class="sheet sheet-condensed">
  <div class="sheet-inner">
    <table class="table">
      <thead>
        <tr>
          <th>Name</th>
          <th>Address</th>
          <th>Location Group</th>
          <th>Active</th>
          <th>Testing for Katie - UPDATED_AT TIME</th>
        </tr>
      </thead>
      <tbody>
      <% @locations.each do |location| %>
        <tr>
          <td><%= link_to(location.name, edit_location_path(location)) %></td>
          <td><%= location.address %></td>
          <td><%= location.location_group.name %></td>
          <td><%= location.active %></td>
          <td><%= location.updated_at.strftime('%l:%M %p') %></td>
        </tr>
      <% end %>
      </tbody>
    </table>
  </div><!-- /.sheet-inner -->
</div><!-- /.sheet -->

<%= will_paginate @locations if @locations.respond_to?(:total_pages) %>

<% content_for :actions do %>
  <%= link_to new_location_path, class: 'btn btn-primary btn-large pull-right' do %>
    <%= icon_tag "plus" %> Add New<br>Location
  <% end %>
<% end %>

EDIT 3

Ok, I just tested my other applications on this server. 2 of the 4 are experiencing this issue. The other 2 are not. All apps on Ruby 1.9.3-p286 and Rails 4.0.0 or 4.0.3 (4.0.0 and 4.0.3 on the "broken" apps, 4.0.0 on the working apps). They're all using the same bootstrap theme. I'm going to go compare the apps now.

EDIT 4 - possible workaround/resolution?

In my controller / index, I changed it to:

  def index
    @locations = Location.sorted.reload
  end

It seems to work, but I'm not sure why I have to do this, nor whether it's a good idea to do so.

Katie M
  • 1,111
  • 6
  • 21
  • 31
  • It might be helpful if you posted the cache related entries from development.rb and config/application.rb. Also you might try: Rails.cache.clear in a console session if your cache configuration is amenable. – laertiades Mar 17 '14 at 20:44
  • I added the full content of my development.rb file. There is nothing cache-related in the application.rb. Maybe that's the issue? I have tried deleting the /tmp/cache folder a few times, and I just tried the Rails.cache.clear in console - neither seem to do the trick. – Katie M Mar 17 '14 at 20:50
  • Maybe it's not Rails but IE, see: http://stackoverflow.com/questions/11082111/prevent-caching-of-pages-in-internet-explorer-8 – Steve Mar 17 '14 at 21:04
  • Hm, so where would I put those response.headers as indicated in the post? `response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" // HTTP 1.1. response.headers["Pragma"] = "no-cache" // HTTP 1.0. response.headers["Expires"] = "0" // Proxies.` – Katie M Mar 17 '14 at 21:54
  • I tried adding the response headers in my application.rb file - no luck. I also tried using the http meta tags per that same post - no luck. – Katie M Mar 17 '14 at 22:00
  • It is not the browser. I just tried it with Firefox and got the same results (even worse, actually). Is there a log somewhere that shows what is being pulled? – Katie M Mar 17 '14 at 22:06
  • you put the response headers in your controller – laertiades Mar 17 '14 at 22:12
  • you put the response headers in your controller. You could put expires_now before your call to render but it doesn't sound like a caching issue. I think passenger adds a development.log file to the log directory. Not sure if db querries are included. YOu might have to adjust your log level. I would put the current time in your index view somewhere to start isolating problem. – laertiades Mar 17 '14 at 22:22
  • Thanks Jesse, I'll try those things. What makes you think it's not a caching issue? What else would render old data? – Katie M Mar 17 '14 at 22:40
  • Rails is set up not to cache in development and your development.rb is using those defaults. Clearing browser cache doesn't fix problem so I don't see how any cache could be getting used. I've never heard of a cache regressing. I would look elsewhere. Perhaps look at the ruby commands used to render the index and enter them directly at the console to make sure they are correct. You might post the index action from your record controller and index.html.(whatever) – laertiades Mar 17 '14 at 23:09
  • Yeah, you're right - it's just so weird. Edited post to include MVC. I hope you see something I don't. – Katie M Mar 18 '14 at 13:56
  • I found a possible fix, but I'm not sure it's a good idea or what its longer-term ramifications may be. See edited post. Thanks for your help. – Katie M Mar 18 '14 at 15:58

0 Answers0