Rails 3.2.8,只有重新启动服务器才能取消缓存模型。

3

我有一个运行在rails 3.2.8上的应用程序。

只有当我重新启动服务器时,模型才会更新,对它们所做的任何更改都不会显示,直到重新启动服务器。

我正在开发中运行,并且关闭了缓存类。

还有其他人遇到这个问题吗?我真的很需要帮助。谢谢。

我已经重新安装了rvm、ruby和我的gemset。

我已经尝试了我所能想到的一切来解决它。感谢大家的关注。

编辑:我在下面添加了大量的配置细节...

development.rb

XXXXX::Application.configure do
  config.cache_classes = false
  config.whiny_nils = true
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :sendmail
  config.active_support.deprecation = :log
  config.action_dispatch.best_standards_support = :builtin
  config.active_record.mass_assignment_sanitizer = :strict
  config.active_record.auto_explain_threshold_in_seconds = 0.5
  config.assets.compress = false
  config.assets.debug = true
  config.action_mailer.default_url_options = { :host => 'yyyy.xxxx.net' }

  #this is an attempt to fix the issues, didn't work
  config.to_prepare do
    ['algorithm', 'key_dates', 'roles', 'status'].each do | file_name |
      require "#{Rails.root}/app/models/user/#{file_name}.rb"
    end
  end

end

我的用户模型包含了一些模块,像这样:

class User < ActiveRecord::Base
  include Status, Roles, KeyDates, Algorithm
  #.....
end

模块的定义如下所示。
module User::Status

  def self.included(base)
    base.class_eval do
      extend ClassMethods
      include InstanceMethods
    end
  end
  #.....
end

Application.rb

require File.expand_path('../boot', __FILE__)

require 'csv'
require 'rails/all'

if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module XXXXX
  class Application < Rails::Application
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.active_record.whitelist_attributes = true
    config.assets.enabled = true
    config.assets.version = '1.0'
    config.autoload_paths += Dir["#{config.root}/app/models/**/"]
    config.to_prepare do
      Devise::Mailer.layout "mailout"
      Devise::Mailer.helper :application
    end
  end
end

GemLock:

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.8)
      actionpack (= 3.2.8)
      mail (~> 2.4.4)
    actionpack (3.2.8)
      activemodel (= 3.2.8)
      activesupport (= 3.2.8)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.0)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.1.3)
    activemodel (3.2.8)
      activesupport (= 3.2.8)
      builder (~> 3.0.0)
    activerecord (3.2.8)
      activemodel (= 3.2.8)
      activesupport (= 3.2.8)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activeresource (3.2.8)
      activemodel (= 3.2.8)
      activesupport (= 3.2.8)
    activesupport (3.2.8)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    addressable (2.2.8)
    arel (3.0.2)
    aws-sdk (1.5.2)
      httparty (~> 0.7)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
      uuidtools (~> 2.1)
    bcrypt-ruby (3.0.1)
    builder (3.0.0)
    cocaine (0.2.1)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.3.3)
    devise (2.1.0)
      bcrypt-ruby (~> 3.0)
      orm_adapter (~> 0.0.7)
      railties (~> 3.1)
      warden (~> 1.1.1)
    devise_invitable (1.0.2)
      devise (>= 2.0.0)
      rails (~> 3.0)
    erubis (2.7.0)
    execjs (1.3.2)
      multi_json (~> 1.0)
    faker (1.0.1)
      i18n (~> 0.4)
    heroku (2.25.0)
      launchy (>= 0.3.2)
      netrc (~> 0.7.1)
      rest-client (~> 1.6.1)
      rubyzip
    hike (1.2.1)
    httparty (0.8.3)
      multi_json (~> 1.0)
      multi_xml
    i18n (0.6.0)
    journey (1.0.4)
    jquery-rails (2.0.2)
      railties (>= 3.2.0, < 5.0)
      thor (~> 0.14)
    json (1.7.5)
    launchy (2.1.0)
      addressable (~> 2.2.6)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.19)
    multi_json (1.3.6)
    multi_xml (0.5.1)
    mysql2 (0.3.11)
    netrc (0.7.1)
    nokogiri (1.5.2)
    orm_adapter (0.0.7)
    paperclip (2.7.0)
      activerecord (>= 2.3.0)
      activesupport (>= 2.3.2)
      cocaine (>= 0.0.2)
      mime-types
    pg (0.13.2)
    polyglot (0.3.3)
    rack (1.4.1)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rails (3.2.8)
      actionmailer (= 3.2.8)
      actionpack (= 3.2.8)
      activerecord (= 3.2.8)
      activeresource (= 3.2.8)
      activesupport (= 3.2.8)
      bundler (~> 1.0)
      railties (= 3.2.8)
    railties (3.2.8)
      actionpack (= 3.2.8)
      activesupport (= 3.2.8)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (0.9.2.2)
    rdoc (3.12)
      json (~> 1.4)
    redcarpet (1.17.2)
    rest-client (1.6.7)
      mime-types (>= 1.16)
    rubyzip (0.9.8)
    sass (3.1.18)
    sass-rails (3.2.5)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    sequel (3.20.0)
    sinatra (1.0)
      rack (>= 1.0)
    sprockets (2.1.3)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.6)
    taps (0.3.24)
      rack (>= 1.0.1)
      rest-client (>= 1.4.0, < 1.7.0)
      sequel (~> 3.20.0)
      sinatra (~> 1.0.0)
    thor (0.16.0)
    tilt (1.3.3)
    treetop (1.4.10)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.33)
    uglifier (1.2.4)
      execjs (>= 0.3.0)
      multi_json (>= 1.0.2)
    uuidtools (2.1.2)
    warden (1.1.1)
      rack (>= 1.0)

PLATFORMS
  ruby

DEPENDENCIES
  aws-sdk
  coffee-rails (~> 3.2.1)
  devise
  devise_invitable
  faker
  heroku
  jquery-rails
  mysql2
  paperclip (~> 2.7)
  pg
  rails (= 3.2.8)
  redcarpet (= 1.17.2)
  sass-rails (~> 3.2.3)
  sqlite3
  taps
  uglifier (>= 1.0.3)

你的模型是否在 vendor/plugins/whatever 插件中声明?当我更改插件中的模型/控制器时,也会发生同样的情况。 - Pablo
你使用的操作系统是什么? - John
如果你解决了这个问题,我很想听听解决方案。我也遇到了同样的问题——只有模型无法取消缓存;控制器和其他部分都正常工作。 - bhuga
@Pablo,这是故意的。所有vendor/和lib/文件仅在启动时加载一次。然而,app/中的文件应在每个页面请求时刷新(如果它们有任何更改,正如Perello在下面指出的那样)。 - Isaac Betesh
4个回答

2
你的问题可以通过重新加载部分取消。这里有一个(与Rails 3.2不兼容的)gem,只在开发环境中重新加载修改后的类。你可以寻找等价的Gem或使其兼容。

https://github.com/paneq/active_reload

您还可以将reload!与guard组合使用。https://github.com/guard/guard 当服务器启动时,它是否显示开发模式?(我猜您要求它以开发模式启动,但它是否真的以dev模式启动?)。
更新:
关于Rails 3.2的说明(官方网站):
最明显的新功能是开发模式变得更快了。受Active Reload的启发,我们现在只会重新加载您实际更改的文件中的类。对于大型应用程序来说,差异非常明显。参见:http://weblog.rubyonrails.org/2012/1/20/rails-3-2-0-faster-dev-mode-routing-explain-queries-tagged-logger-store/ 因此,由于某种原因,Rails无法检测到您的文件系统中的更改。
更新2:
检查一下你的资源是否存储在无效的文件夹中(从Linux的角度来看)。我的意思是,如果Rails使用相对路径(不确定),那么C:\ invalid linux folder \ something \ rails \ my_apps可能有效。但是,如果Rails重新加载使用绝对路径,无论原因如何,你就完了。

2

如果没有看到您的项目文件(尤其是Gemfile,config/environments/development.rb和application.rb),很难给出明确的建议。但是您可以始终生成全新的Rails项目,并在几分钟内将当前项目文件逐个传输到最近创建的项目中,以确定导致问题的确切 gem 或文件。之后,修复问题会更容易,希望能帮到您。这可能有点暴力,但在紧急情况下可以提供帮助。


谢谢,我已经在帖子中添加了很多细节,例如配置和gemfiles。 - CafeHey

1

请将您的 config/environments/development.rb 文件与我的进行比较:

SampleApp::Application.configure do

  config.cache_classes = false
  config.whiny_nils = true
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.delivery_method = :letter_opener
  config.active_support.deprecation = :log
  config.action_dispatch.best_standards_support = :builtin
  config.active_record.mass_assignment_sanitizer = :strict
  config.active_record.auto_explain_threshold_in_seconds = 0.5
  config.assets.compress = false
  config.assets.debug = true
  config.domain = '.lvh.me'
end

谢谢,我已经放入我的开发文件并进行了编辑,一切看起来都很好。 - CafeHey

0

在 development.rb 中尝试以下代码:

config.reload_classes_only_on_change = false


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接