views:

220

answers:

2

Hi there,

I'm trying to work out why when working on a 404 page on a rails app I'm working, the only way to see changes I've made to the html on the page is to physically restart the webserver with a ctrl-C followed by a call to script/server.

As far as I can tell, I can't see anything particularly wrong with the development.rb config file here:

# Settings specified here will take precedence over those in config/environment.rb

# In the development environment your application's code is reloaded on
# every request.  This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs                         = true
config.action_controller.perform_caching             = false

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = false

# add rack bug
# config.middleware.use "Rack::Bug"

#  this disables the caching for comatose, not the rest of the app
#  config.disable_caching = true

config.action_mailer.default_url_options = { :host => "localhost:3000" }

config.gem "thoughtbot-factory_girl",
             :lib    => "factory_girl",
             :source => "http://gems.github.com"

This alone won't display the error pages locally, so in application_controller.rb I've aliased rescue_action_locally to the rescue_action_in_public method, to stop me seeing the stacktrace:

 #  this method allows you to test 404 and 500 pages locally
 alias_method :rescue_action_locally, :rescue_action_in_public

This here shows me the error page once, but then caches it so that future reloads show the state of the html file when the server was loaded.

The log output doesn't show me any weird caching behaviour - it's getting a request for a non-existent resource, not finding anything, then rendering the html page as required:

  chrisadams@r220-101-174-100 ~/RailsApps/annoying_app > script/server --debugger
  => Booting Mongrel
  => Rails 2.3.2 application starting on http://0.0.0.0:3000
  => Debugger enabled
  => Call with -d to detach
  => Ctrl-C to shutdown server
    SQL (0.2ms)   SET SQL_AUTO_IS_NULL=0

  Processing ApplicationController#index (for 127.0.0.1 at 2009-12-28 19:23:27) [GET]

  ActionController::RoutingError (No route matches "/non-existent-resource" with {:method=>:get}):

  Rendering /Users/chrisadams/RailsApps/annoying_app/public/404.html (404 Not Found)

The 404.html is totally static, without any ERB in there at all, and this static html page is what isn't changing between page refreshes.

What am I doing wrong here? This is driving me crazy!

+1  A: 

I've noticed that not everything is reloaded on every request, even in development mode. Is your 404.html page completely static, or are you running it through ERB or something?

rescue_from is also becoming the generally preferred means of doing this nowadays.

Azeem.Butt
I'm not sure why, but using `rescue_from` seems to have cleared up the strange caching issue here. Thanks for the tip.
Chris Adams
A: 

I'm not sure if this might help you, but one time I accidentally uncommented the lines ENV['RAILS_ENV'] ||= 'production' in environment.rb and my app started in production mode even when I didn't specify the environment.

Could that be the case for you?

Senthil