Rails控制台:重新加载!没有反映模型文件的变化?可能的原因是什么?

Mad*_*hik 93 ruby config ruby-on-rails reload 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'
Run Code Online (Sandbox Code Playgroud)

这是application.rb的config部分

 # 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
Run Code Online (Sandbox Code Playgroud)

当我运行重装!在rails console上它返回true

Naz*_*ain 170

reload!仅在控制台环境中重新加载最新代码.它不会重新初始化现有对象.

这意味着如果您已经实例化了任何对象,则不会更新其属性 - 包括新引入的验证.但是,如果创建新对象,则其属性(以及验证)将反映重新加载的代码. 更多在这里

  • 它将反映您重新初始化对象的时间. (2认同)

cti*_*ide 17

你是从数据库重装对象吗?

例如:

>> a = User.last
=> #<User id: 16, email: "asdfadsf@sdfdsf.com">
>> reload!
Reloading...
=> true
Run Code Online (Sandbox Code Playgroud)

在从db重新加载之前,'a'不会反映模型的任何更改.