如何让 Sinatra 在每次更改后自动重新加载文件?
我正在使用
# my_app.rb
load 'index.rb'
并启动这样的服务器
ruby my_app.rb
,但它永远不会重新加载我在索引页面中所做的任何更改。
我在这里错过了什么吗?
I am using
# my_app.rb
load 'index.rb'
and start the sever like this
ruby my_app.rb
but it never reload any changes I made in index page.
Did I miss anything here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
请参阅 Sinatra 常见问题解答、
"如何让我的 Sinatra 应用程序在更改时重新加载?"
See the Sinatra FAQ,
"How do I make my Sinatra app reload on changes?"
注意:它只会重新加载 sinatra 处理程序(也许还有一些 sinatra 服务器配置命令),但不会重新加载自定义文件,您必须手动重新加载这些文件。
9年后的UPD:似乎已经可以使用
also_reload
、dont_reload
和after_reload
重新加载其他文件 - - https://github.com/sinatra/sinatra/pull/1150Note: it will reload only sinatra handlers (and, maybe some sinatra server configuration commands), but not custom files, which you have to reload manually.
UPD after 9 years: seems like it is already possible to reload other files using
also_reload
,dont_reload
andafter_reload
-- https://github.com/sinatra/sinatra/pull/1150您可以使用
rerun
gem。或者如果您使用的是rackup
You can use the
rerun
gem.OR if you are using rackup
gem install sinatra-reloader
您可能需要将环境变量设置为开发并有条件地加载 gem。
gem install sinatra-reloader
You may want to set environment variable to development and conditionally load the gem.
当您使用 Passenger Standalone 运行应用程序时,只需创建一个
tmp/always_restart 文件:
请参阅 Passenger 文档了解更多信息。
When you run the application with Passenger Standalone, just create a
tmp/always_restart
file:See Passenger documentation for more info.
我喜欢霰弹枪宝石。 如果您使用模块化 Sinatra 应用程序并拥有 config.ru 文件,则很容易运行。
此处查看该 gem。 它相当简单,无需配置。
I like the Shotgun gem. If you're using a modular Sinatra app and have a config.ru file it's easy to run.
Check the gem out here. It's fairly straight forward and no configuration needed.
在 Windows 上,我使用 restart gem 来实现此目的:
或者,使用rackup:
请参阅 此处了解更多信息,希望您发现它有用。
On Windows, I am using my restart gem for this:
or, with rackup:
See here for more info, hope you find it useful.
你可以使用防护架。 摘自 dblock.org 上的文章:
添加此内容到您的 Gemfile:
然后,在项目的根目录中创建一个包含以下内容的
Guardfile
:最后,运行 Guard,如下所示:
bundle execguard
和rackup
每次都会重新加载。You could use guard-rack. Lifted from an article at dblock.org:
Add this to your Gemfile:
Then, create a
Guardfile
at the root of your project with this content:Lastly, run Guard, like so:
bundle exec guard
, andrackup
will reload every time.如果您只更改模板,那么如果您将环境设置为开发,sinatra 将始终重新渲染它们:
If you only change your templates sinatra will always rerender them if you set your environment to development: