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.