我今晚创建了一个新的rails应用程序(v.4.2.5),在ActiveRecord
和ActiveModel
内进行了一些实验。在修改了一些gems代码后,我注意到在启动/重启rails控制台时出现了一些意外行为。
运行bundle open activemodel
使用p
语句修改方法,保存文件。 (截断的片段)。
def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc:
p '+++++++++++++++++++++++++++++++++++++++++++++++++++'
打开rails c
调用将调用此方法的内容。
Loading development environment (Rails 4.2.5)
2.2.2 :001 >
2.2.2 :001 > Product.new
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++++++++++++++++++++++++++++++++++++++++++"
=> #<Product id: nil, in_stock: nil, name: nil>
2.2.2 :002 >
返回修改后的文件并注释掉我的p
语句,保存文件。
def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc:
#p '+++++++++++++++++++++++++++++++++++++++++++++++++++'
在rails控制台中运行reload!
并重新调用Product.new
提供与步骤2相同的输出。退出rails控制台并使用rails c
重新启动也会给我同样的结果输出为步骤2.
我希望退出rails控制台并重新启动会重新初始化&#34; rails加载过程(因此重新加载ActiveModel
),似乎并非如此。我发现反映变化的唯一方法是完全退出我的shell。
如果有人可以请解释为什么我必须完全退出shell才能看到我在宝石中所做的更改?难道我不能简单地退出/重新启动rails控制台吗?
我通过略读rails guides得到的印象是,调用rails c
会启动启动序列,就像rails s
谢谢!
答案 0 :(得分:0)
我已经看到此设置会影响该行为:
在config / environments / development.rb
打开
config.eager_load = true