为什么我需要再次运行我的sinatra应用程序时进行更改和我的环境不是:开发



我刚刚为我的Sinatra应用程序实现了Compass配置,但是当我将环境更改为:test:production并修改我的文件如screen.sassindex.haml时,我的更改没有反映在我重新加载页面时,所以我需要再次运行我的应用程序?

正常吗?只有我吗?

这是我的app.rb文件的样子:

require 'sinatra'
require 'haml'
require 'sass'
require 'compass'
require './helpers.rb'
configure do
  set :environment, :test
  Compass.configuration do |config|
    settings.environment == :production ? 
      config.output_style = :compressed : 
      config.output_style = :nested
    settings.environment == :development ?
      config.line_comments = true :
      config.line_comments = false
  end
  set :sass, Compass.sass_engine_options
end
before do
  @js = 'javascript:;'
end
get '/scripts/jquery.js' do
  # Downloads the latest jQuery 1.x version when needed. Requires to reload the page after done.
  `curl "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" >> public/scripts/jquery.js`
end
get '/styles/:name.css' do
  sass :"styles/#{params[:name]}"
end
get '/?' do
  haml :index
end
get '/:page/?' do
  haml params[:page].to_sym
end

任何想法?

一般来说,如果您对正在运行的Sinatra应用程序进行更改,则必须重新启动该应用程序,因为该程序已经加载到内存中。

在Sinatra FAQ中有自动检测更改和重新启动应用程序的选项。

既然Shotgun部分修复了这个问题(重新加载你的生产文件,也许可以尝试使用Sinatra::Reloader, IMHO,比Shotgun工作得更好。

可能是(未测试)

require "sinatra"
configure(:production) do |c|
  require "sinatra/reloader"
  c.also_reload "*.sass", "*.haml"
end

也就是说,您确定在生产/测试环境中需要这种行为来进行更新吗?开发env。对于这种热测试,

我曾经使用sinatra::reloader但我不喜欢产生的巨大依赖(我们都应该注意有多少宝石被激活)

手枪(在0.0.2版本的稚嫩年龄),我认为很好地完成了所需的工作

我使用shotgum gem。

gem install shotgun
然后

shotgun app.rb  

从应用程序目录

这将在每次请求时重新加载应用程序,而不是将整个应用程序保存在内存中。您访问localhost:9393

最新更新