How to get Sinatra to auto-reload the file after e

2019-01-16 02:18发布

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?

标签: ruby sinatra
9条回答
地球回转人心会变
2楼-- · 2019-01-16 02:34

If you only change your templates sinatra will always rerender them if you set your environment to development:

ruby app.rb -e development
查看更多
等我变得足够好
3楼-- · 2019-01-16 02:37

I like the Shotgun gem. If you're using a modular Sinatra app and have a config.ru file it's easy to run.

shotgun config.ru

Check the gem out here. It's fairly straight forward and no configuration needed.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-16 02:41

You could use guard-rack. Lifted from an article at dblock.org:

Add this to your Gemfile:

group :development do
  gem "guard"
  gem "guard-bundler"
  gem "guard-rack"
end

Then, create a Guardfile at the root of your project with this content:

guard 'bundler' do
  watch('Gemfile')
end

guard 'rack' do
  watch('Gemfile.lock')
  watch(%r{^(config|app|api)/.*})
end

Lastly, run Guard, like so: bundle exec guard, and rackup will reload every time.

查看更多
对你真心纯属浪费
5楼-- · 2019-01-16 02:42

gem install sinatra-reloader

require 'sinatra/base'
require "sinatra/reloader"

class MyApp < Sinatra::Base
  register Sinatra::Reloader

  get '/' do
    "Hello Testing1!"
  end
end

You may want to set environment variable to development and conditionally load the gem.

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-16 02:43

On Windows, I am using my restart gem for this:

restart ruby my_app.rb

or, with rackup:

restart rackup

See here for more info, hope you find it useful.

查看更多
Summer. ? 凉城
7楼-- · 2019-01-16 02:52

gem install sinatra-reloader

require 'sinatra'
require 'sinatra/reloader'

Note: it will reload only sinatra handlers (and, maybe some sinatra server configuration commands), but not custom files, which you have to reload manually.

查看更多
登录 后发表回答