Rails控制台应用程序初始化

时间:2016-02-26 02:13:51

标签: ruby-on-rails ruby-on-rails-4 initialization rubygems

我今晚创建了一个新的rails应用程序(v.4.2.5),在ActiveRecordActiveModel内进行了一些实验。在修改了一些gems代码后,我注意到在启动/重启rails控制台时出现了一些意外行为。

实施例

  1. 运行bundle open activemodel使用p语句修改方法,保存文件。 (截断的片段)。

    def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc:
     p '+++++++++++++++++++++++++++++++++++++++++++++++++++'
    
  2. 打开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 >
    
  3. 返回修改后的文件并注释掉我的p语句,保存文件。

    def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc:
     #p '+++++++++++++++++++++++++++++++++++++++++++++++++++'
    
  4. 在rails控制台中运行reload!并重新调用Product.new提供与步骤2相同的输出。退出rails控制台并使用rails c重新启动也会给我同样的结果输出为步骤2.

  5. 期望 - 问题

    我希望退出rails控制台并重新启动会重新初始化&#34; rails加载过程(因此重新加载ActiveModel),似乎并非如此。我发现反映变化的唯一方法是完全退出我的shell。

    如果有人可以请解释为什么我必须完全退出shell才能看到我在宝石中所做的更改?难道我不能简单地退出/重新启动rails控制台吗?

    我通过略读rails guides得到的印象是,调用rails c会启动启动序列,就像rails s谢谢!

1 个答案:

答案 0 :(得分:0)

我已经看到此设置会影响该行为:

在config / environments / development.rb

打开

config.eager_load = true