How to get Rails 3 to reload STI classes in design mode?

After migrating to Rails 3, I noticed that I needed to restart my server in order to reload the STI model classes with each request. For example, suppose I have this:

# app/models/vehicle.rb class Vehicle < ActiveRecord::Base end # app/models/car.rb class Car < Vehicle end 

If I made a change to Vehicle , the change will be loaded on the next request. But if I made changes to Car , I have to restart my server to boot.

Any ideas on fixing this?

I am running WEBrick, but I am not ready for this.

+3
source share
3 answers

We found that to complete this work, we needed both a zeta solution and some additional code (at least in Rails 3.0.9). For the above problem, the solution would look something like this:

In config / environment / development.rb:

  config.after_initialize do ["vehicle"].each do|dep| require_dependency( (Rails.root + "app/models/#{dep}").to_s ) end end 

In application / controllers / application_controller.rb:

 class ApplicationController < ActionController::Base if Rails.env == 'development' require_dependency( (Rails.root + "app/models/vehicle").to_s ) end ... 

The code in development.rb handles the bootstrap of the class, and the code in ApplicationController handles subsequent requests.

+2
source

I believe this can be solved by adding require_dependency 'vehicle' to the controller.

+1
source

Using rails 3.0.3 and passenger 3, I do not see this at all. If updating your application to version 3.0.3 is not fixed, I would disable WEBrick.

I personally recommend using something other than WEBrick. Passenger has long been my server of choice for development + production.

0
source

All Articles