我最近一直在研究Rails,出于测试目的,我需要从默认的WEBrick服务器切换到支持多线程的服务器。我选择使用Puma,它可以通过gem和development.rb文件中的一行轻松配置。
Development.rb:
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
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_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
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.threadsafe!
我需要添加的唯一一行是最终的“config.threadsafe!”这里参考的是Gemfile。
的Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem "better_errors"
gem "binding_of_caller"
gem 'puma'
end
gem 'jquery-rails'
gem 'devise'
gem 'paperclip'
gem 'cocaine', '= 0.3.2'
gem 'streamio-ffmpeg'
gem 'cancan'
gem 'formtastic'
gem 'jbuilder'
# Deploy with Capistrano
gem 'capistrano'
gem 'rvm-capistrano'
# To use debugger
#gem 'debugger'
gem 'jquery-validation-rails'
这最终满足了我需要它的目的,并且应用程序正常运行。问题是,每当我对任何东西(JS,CSS,控制器,视图等)进行更改时,更改都不会显示,直到我重新启动服务器。
任何人都可以解释为什么会这样吗?更重要的是,我该怎么做才能更改它,以便不需要重新启动服务器才能显示更改?
答案 0 :(得分:1)
通过将config.threadsafe!
添加到您的development.rb文件,您将禁用自动代码重新加载。请参阅实施here:
# Enable threaded mode. Allows concurrent requests to controller actions and
# multiple database connections. Also disables automatic dependency loading
# after boot, and disables reloading code on every request, as these are
# fundamentally incompatible with thread safety.
def threadsafe!
self.preload_frameworks = true
self.cache_classes = true
self.dependency_loading = false
self.allow_concurrency = true
self
end
您应该从development.rb中删除config.threadsafe!
。