[ruby-on-rails] Rails Console : 재 장전! 모델 파일의 변경 사항을 반영하지 않습니까? 가능한 이유는 무엇입니까?

이전에는 잘 작동했습니다. 나는 약간의 구성을하고있다. 그래서 내가 모르는 사이에 일부 구성을 변경했을 수 있습니다.

여기 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'

다음은 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

내가 reload를 실행할 때! 레일 콘솔에서는 true를 반환합니다.



답변

reload!콘솔 환경에서 최신 코드 만 다시로드합니다. 기존 개체를 다시 초기화하지 않습니다.

즉, 이미 개체를 인스턴스화 한 경우 새로 도입 된 유효성 검사를 포함하여 해당 속성이 업데이트되지 않습니다. 그러나 새 개체를 만드는 경우 해당 특성 (및 유효성 검사)은 다시로드 된 코드를 반영합니다.
여기에 더


답변

데이터베이스에서 개체를 다시로드하고 있습니까?

예를 들면 :

>> a = User.last
=> #<User id: 16, email: "asdfadsf@sdfdsf.com">
>> reload!
Reloading...
=> true

‘a’는 db에서 다시로드 할 때까지 모델의 변경 사항을 반영하지 않습니다.


답변