Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

ruby - Sinatra + Bundler?

I'm wondering how one can use Bundler with Sinatra. The idea is to use the gems that Bundler downloads inside the .gems folder.

question from:https://stackoverflow.com/questions/1706120/sinatra-bundler

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Inside your Sinatra app, you just have to require the bundler setup:

require "bundler/setup"
require "sinatra"

get "/" do
  "Hello world!"
end

Alternatively, if you don't want to add the additional require "bundler/setup" at the top of your app, you can instead invoke sinatra via bundle exec (e.g. bundle exec ruby myapp.rb)

This assumes that you have a Gemfile in the root of your application. It might look like this:

source "http://rubygems.org"

gem "sinatra"

This also assumes that you've already installed bundler (gem install bundler) and that you ran bundle install to install all the gem dependencies.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...