Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.1 Not Reloading Changed Views
    text
    copied!<p>I'm seeing a bug/feature in my Ruby 1.9.2 applications. Any changes to <strong>views</strong> (not ruby files) require a server restart. I initially encountered this in a Rails app, but I've tested the same thing in a minimal Sinatra app too.</p> <p>I'll include a simple app to demonstrate</p> <pre><code># testapp.rb require 'sinatra' get '/' do [0,1,2].to_s #change this to [0,1].to_s end </code></pre> <p>This is my procedure:</p> <ul> <li><code>ruby testapp.rb</code> (runs thin server for me)</li> <li>load the page</li> <li>open the file and edit the view</li> <li>reload the page (I see no changes)</li> <li>kill the server</li> <li>restart the server (changes now visible)</li> </ul> <p>I've been developing in Ruby 1.8.7 on Rails 3 for the last several months. Having to restart the server on any view change slows down development severely.</p> <p>I've ready <a href="https://stackoverflow.com/questions/5027327/rails-development-environment-not-reloading-views-on-change">this SO thread</a>, but in my version of Rails (3.1.0 rc4), the config variable is already set as per that answer. Additionally I can replicate the error using Sinatra, so that doesn't seem like it's the case.</p> <p>Can anyone shed light on this issue?</p> <p>Ruby version: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] Server: thin 1.2.11 (also tested this with Sinatra/Webrick)</p> <p><strong>EDIT 7/13, Clarification</strong> The Sinatra thing is a separate issue--Sinatra's source reloading is disabled by default. I used this code to test out the behavior:</p> <pre><code>require 'sinatra' require 'sinatra/reloader' require 'haml' set :views, 'views' get '/' do end get '/test' do haml :test end </code></pre> <p>With this, I made a file: <code>views/test.haml</code>. Modifying it while the server is running <strong>does</strong> show a change when the page is reloaded. Thanks to Tiredpixel for pointing this out</p> <p><strong>Unresolved Issue</strong>: why does Rails 3.1 on Ruby 1.9.2 not reload the <strong>views</strong>? I'm able to get ruby files to load, but not haml and erb files. I end up restarting the server just to see if a bug was actually fixed (or not fixed) because of a file not loading properly.</p> <p><strong>EDIT/SOLUTION (copied from my comment in the accepted answer)</strong>:</p> <p>The problem was in <code>config/environments/development.rb</code></p> <pre><code>config.cache_classes = false </code></pre> <p>Even after we checked this was correct, we still had the issue. Further down in the file we had: </p> <pre><code>config.threadsafe! </code></pre> <p>What this does is set the following 3 flags to true: <code>config.allow_concurrency</code>, <code>config.preload_frameworks</code>, and (surprise!) <code>config.cache_classes</code>.</p> <p>To fix: move <code>config.threadsafe!</code> above <code>config.cache_classes</code>, so that it doesn't get implicitly overridden.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload