Ruby-on-rails 每次我进行更改时,Rails Server 都需要重新启动吗?为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18270945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails Server needs restart every time I make changes? why?
提问by Amit Sharma
Every time I change anything in controller's or in models, I have to restart the server for it to take effect.But that wasn't always the case, it used to work normally before, when I changed anything, but i don't know what happened now ?
每次我更改控制器或模型中的任何内容时,我都必须重新启动服务器才能使其生效。但情况并非总是如此,以前它可以正常工作,当我更改任何内容时,但我不知道现在发生什么事 ?
My Rails version is 3.2.11
我的 Rails 版本是3.2.11
In my development environment file i have set config.cache_classes = false.
在我的开发环境文件中,我设置了 config.cache_classes = false。
Please help..
请帮忙..
My development.rb file is as follows
我的development.rb文件如下
Testapp::Application.configure do
# 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.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
回答by Amit Sharma
I have got the answer..
我得到了答案..
After adding following line in my config/environments/development.rbfile my issue has been resolved.
在我的config/environments/development.rb文件中添加以下行后,我的问题已解决。
config.reload_classes_only_on_change = false
回答by jayesh
start your server using below command in console
在控制台中使用以下命令启动您的服务器
rails server -e development
if not started then give your rails version and which sever you use for run rails application.
如果未启动,请提供您的 rails 版本以及您用于运行 rails 应用程序的服务器。
more Configuration
更多配置
modify your config/environments/development.rbfile to:
将您的config/environments/development.rb文件修改为:
config.serve_static_assets = false
回答by Beauty
There is a good note for VirtualBoxusers, posted as comment by user Ninjaxor:
对于VirtualBox用户,有一个很好的说明,由用户 Ninjaxor 作为评论发布:
For Vagrant/ virtual box users, there's a bug where if the host clock and guest clock are out of sync, it borks rails' reloader. https://github.com/rails/rails/issues/16678
对于 Vagrant/virtual box 用户,有一个错误,如果主机时钟和访客时钟不同步,它会破坏 rails 的重新加载器。 https://github.com/rails/rails/issues/16678
The file Vagrantfileyou find in a directory like this:
.../ruby/gems/sass-3.4.22/vendor/listen
Vagrantfile您在这样的目录中找到的文件:
.../ruby/gems/sass-3.4.22/vendor/listen
There you have to add this:
在那里你必须添加这个:
# Sync time every 5 seconds so code reloads properly
config.vm.provider :virtualbox do |v|
v.customize ["guestproperty", "set", :id, "--timesync-threshold", 5000]
end
Thanks to user axsuul on GitHub!
感谢 GitHub 上的用户 axsuul!
回答by Jessica Grayson
An additional situation where this can come up is in a virtualized environment where the files are being edited on the host operating system, and the guest operating system's file event manager doesn't generate events for file changes.
另一种可能出现的情况是在虚拟化环境中,文件正在主机操作系统上被编辑,并且来宾操作系统的文件事件管理器不会为文件更改生成事件。
A solution for this situation is to comment out the following line in config/environments/development.rb:
这种情况的解决方案是注释掉以下行config/environments/development.rb:
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
Thus giving:
因此给出:
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This forces rails to actually check file modification times instead of expecting to get filesystem events.
这会强制 rails 实际检查文件修改时间,而不是期望获取文件系统事件。
回答by rjferguson
I noticed that setting
我注意到设置
config.cache_classes = false
is what did the trick for me.
是什么对我有用。

