2011-03-25 22 views
84

此前它工作正常。我一直在玩一點配置。所以可能是我在不知不覺中改變了一些配置。Rails控制檯:重新加載!沒有反映模型文件的變化?什麼可能是可能的原因?

這裏是環境的配置/ 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 

配置節!在軌道控制檯它返回true

回答

141

reload!只在控制檯環境中重新加載最新的代碼。它不重新初始化現有對象。

這意味着如果您已經實例化任何對象,則其屬性將不會更新。但是,如果您創建新對象,則其屬性將反映重新加載的代碼。 more here

+0

自定義驗證如何?我已經定義了一些方法並用validate進行了註冊。當我更改驗證邏輯時,它不會反映在重新加載! – 2011-03-25 07:18:42

+2

它會反映您何時重新初始化對象。 – 2011-03-25 08:48:38

15

您是否正在從數據庫重新加載對象?

例如:

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

「一」,直到你從數據庫中重新加載它不會反映到模型中的任何改變。

+1

注 - 即使在訪問對象的方法時也是如此。例如,如果更改了類方法foo()的定義,則在控制檯中,除非首先重新加載a,否則a.foo將不會使用新定義。 – jpwynn 2013-06-12 00:29:34

相關問題