How to get Sinatra to auto-reload the file after each change?

后端 未结 9 449
梦谈多话
梦谈多话 2020-12-07 09:39

I am using

# my_app.rb
load \'index.rb\'

and start the sever like this

ruby my_app.rb

but it never relo

相关标签:
9条回答
  • 2020-12-07 10:09

    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.

    0 讨论(0)
  • 2020-12-07 10:09

    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.

    0 讨论(0)
  • 2020-12-07 10:12

    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.

    0 讨论(0)
提交回复
热议问题