# Intermittent page loads in Ruby on Rails app

**URL:** <https://www.ruby-forum.com/t/intermittent-page-loads-in-ruby-on-rails-app/211030>\
**Category:** Deployment\
**Created:** [August 24, 2011, 12:43am UTC](https://www.ruby-forum.com/t/intermittent-page-loads-in-ruby-on-rails-app/211030 "2011-08-24T00:43:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 24, 2011, 12:43am UTC](https://www.ruby-forum.com/t/intermittent-page-loads-in-ruby-on-rails-app/211030/1 "2011-08-24T00:43:36Z")

</div>

Hi Everyone, this one’s got me stumped.

I’ve got a ruby on rails site here (rails 2.0.2, ruby 1.8.6, running on  
thins (0.8.2) sitting on top of nginx), and when I hit a certain action  
I sometimes get the correct response, other times I get a 500 error.

The code in this view goes as follows:

def show  
@item = Item.find\_by\_url\_slug(params[:id])

filename = “#{RAILS\_ROOT}/public/#{@item.index.url}”  
@data = File.open(filename, ‘rb’) { |f| f.read } # read data via File.

render :layout =\> false  
end

The view is rather simplistic, with show.html.erb containing

\<%= @data %\>

I’ve suspected caching, and have tried setting a variety of different  
headers (cache-control, expires etc), and also tried the expires\_now()  
method, to no avail.

Out of interest I’ve also tried adding a sleep(2) call in the  
controller, and looking at the network requests it’s obvious on the 500  
pages that this method isn’t being called - none of the above code in  
the show action is.

Furthermore, there’s no evidence of the call in the production.log when  
the page doesnt load, or any errors in the nginx log. So, no errors to  
debug, just the occasional 500 (happening say 2/4 page loads).

I should add that this code works fine locally, and on our staging  
server - it’s only in production that this is an issue.

Any ideas??
