Rails 控制台:重新加载!不反映模型文件中的更改?可能的原因是什么?

发布于 2024-10-26 14:31:35 字数 1215 浏览 2 评论 0原文

早些时候它运行良好。我一直在玩一点配置。所以可能我在不知不觉中改变了一些配置。

这是环境/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'

这是

 # 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

我运行重新加载时application.rb的配置部分!在 Rails 控制台上它返回 true

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫腻 2024-11-02 14:31:35

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

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

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

七七 2024-11-02 14:31:35

您是否从数据库重新加载对象?

例如:

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

“a”不会反映模型的任何更改,直到您从数据库重新加载它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文