Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

reload! doesn't reload

#3822

using reload! in the console does not reload the models.

Rails master clone (from 31st of Jan) on Ruby 1.8.7

To reproduce:

Make a model, users, add a validation:

class User < ActiveRecord::Base
  validates :email, :presence => true
end

Open the console and do the following:

>> u = User.new
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> u.valid?
=> false
>> u.errors
=> #<OrderedHash {:email=>["can't be blank"]}>

# Added in validations on name "validates :name, :presence => true"
>> reload!
Reloading...
=> true
>> u = User.new
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> u.valid?
=> false
>> u.errors
=> #<OrderedHash {:email=>["can't be blank"]}>
# changes to validation on name are missing

Also, reload! not picking up Ruby syntax errors and returns true even with a ruby syntax error, to reproduce:

>> u = User.new
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> u.valid?
=> false
>> u.errors
=> #<OrderedHash {:email=>["can't be blank"]}>

# Added in validations on name "validates :name, :presence true"
# note the missing => in the options hash
>> reload!
Reloading...
=> true
>> u = User.new
=> #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> u.valid?
=> false
>> u.errors
=> #<OrderedHash {:email=>["can't be blank"]}>
# changes to validation on name are missing

Reported by Mikel Lindsaar · January 31st, 2010 @ 01:53 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: High

Activity

  1. RomD
    RomD

    Same problem here.
    I have to close and reopen the console to see the changes after using 'rake db:migrate'.

    February 7th, 2010 @ 08:13 PM

  2. marcolz
    marcolz
    • Tag changed from activerecord, console, reload to activerecord, activeresource, console, reload, reload!

    Same here, also when attempting to reload an ActiveResource::Base class, with Rails 3.0.0.beta.

    February 8th, 2010 @ 11:39 AM

  3. marcolz
    marcolz
    • Tag changed from activerecord, activeresource, console, reload, reload! to development environment, activerecord, activeresource, console, reload, reload!

    It's a problem related not only to the console, but to the entire development environment: even though grep cache_classes config/environments/development.rb reads "config.cache_classes = false", still the models are not reloaded.

    February 8th, 2010 @ 12:02 PM

  4. Fernando Blat
    Fernando Blat

    The actual reload callbacks seem to have been disappeared in the transition to the new callback system for Rails 3.

    I am attaching a patch which restores all the callbacks needed to reset ActiveRecord and ActiveSupport, just like it did in Rails 2.3.x

    February 21st, 2010 @ 04:18 PM

  5. José Valim
    José Valim
    • Assigned user set to José Valim

    February 21st, 2010 @ 07:34 PM

  6. Christos Zisopoulos
    Christos Zisopoulos

    Using reload! in the console is not working for me either (Rails 3.0.0.beta1 and any Ruby 1.8.7/1.9.1)

    The patch seems to fix it.

    +1

    February 24th, 2010 @ 04:31 PM

  7. RomD
    RomD

    Thanks for the patch, seems to work fine.

    February 24th, 2010 @ 11:59 PM

  8. José Valim
    José Valim
    • State changed from new to resolved

    Fixed!

    February 26th, 2010 @ 11:10 AM

  9. Repository
  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to High

    October 15th, 2010 @ 11:01 PM

  11. Tiago Franco
    Tiago Franco

    This is back again on 3.0.3 :(

    February 1st, 2011 @ 10:51 PM

  12. William Denniss
    William Denniss

    This is broken again in 3.0.4.

    I have logged a new bug #6447 reload! doesn't reload for the regression as I see no way to re-open this bug.

    February 18th, 2011 @ 07:43 AM