2013-02-22 67 views
1

嗨,所以我偶然发现了一种新的方式来要求我的红宝石的宝石在我的末日应用程序使用捆绑,我想知道,如果这是我应该怎么做:这是需要红宝石的正确方法吗?

我的宝石文件看起来像:

source 'https://rubygems.org' 
gem 'sinatra' 
gem 'thin' 
gem 'haml' 

我config.ru文件看起来像:

require 'rubygems' 
require 'bundler' 

Bundler.require 

require './web' 
run Sinatra::Application 

我web.rb文件看起来像:

class MyApp 
    before do 
    cache_control :public, :max_age => 60 
    end 

    not_found do 
    haml :not_found 
    end 

    get '/' do 
    haml :index 
    end 
end 

回答

1

从你config.ru文件摆脱这些行:

require 'rubygems' 
require 'bundler' 

Bundler.require 

只要确保你从终端运行

bundle install 

启动应用程序之前安装你的宝石。

+0

嗨,感谢您的建议,此应用程序在heroku上运行,并且我在将它推送到git存储库之前在我的mac上运行软件包安装,因为heroku需要Gemfile.lock。 – 2013-02-22 23:39:27

+0

每次添加gem并在本地重新启动时,应该运行bundle install。 – 2013-02-22 23:49:44

+0

是的,这就是我做的,但是当它运行在服务器上时,我将无法运行捆绑包安装,因此我为什么要询问上述代码 – 2013-02-22 23:54:40