Rails Console: reload! not reflecting changes in model files? What could be possible reason?
Asked Answered
K

2

102

Earlier it was working fine. I have been playing little bit config. So may be i have changed some config unknowingly.

here is config of environment/development.rb

  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.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

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin

  # migration prefix with sequence #s
  config.active_record.timestamped_migrations = false

  #time zone
  config.time_zone = 'UTC'

Here is config section of application.rb

 # Configure the default encoding used in templates for Ruby 1.9.
 config.encoding = "utf-8"

 # Configure sensitive parameters which will be filtered from the log file.
 config.filter_parameters += [:password]

 config.active_record.schema_format = :sql

when i run reload! on rails console it return true

Knickerbocker answered 25/3, 2011 at 1:30 Comment(0)
N
191

reload! only reloads the latest code in the console environment. It does not re-initialize existing objects.

This means if you have already instantiated any objects, their attributes would not be updated - including newly introduced validations. However, if you create a new object, its attributes (and also validations) will reflect the reloaded code. more here

Nethermost answered 25/3, 2011 at 4:4 Comment(2)
What about custom validation? I have defined some methods and registered with validate. When i change validation logic, its not reflected on reload!.Knickerbocker
It will reflect when you re-initialize the object.Nethermost
M
21

Are you reloading the object from the database?

For example:

>> a = User.last
=> #<User id: 16, email: "[email protected]">
>> reload!
Reloading...
=> true

'a' won't reflect any changes to your model until you reload it from the db.

Must answered 25/3, 2011 at 4:0 Comment(1)
Note - this is true even when accessing a method on an object. Eg, if you change the definition of the class method foo(), then in the console a.foo will not use the new definition unless you first reload a.Hansen

© 2022 - 2024 — McMap. All rights reserved.