为什么Bundler.require加载错误的路径?

时间:2021-06-07 00:18:17

I'm having a problem with Bundler and Sinatra. First i used this in my app.rb:

我遇到了Bundler和Sinatra的问题。首先我在app.rb中使用了这个:

require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'haml'
require 'redis'
...

However I read about Bundler.require and thought it's a nice DRY way because the gems specified in Gemfile are the ones I will require in my app anyway. Why should I specify the requires again in app.rb? So I changed my code to:

但是我读了Bundler.require并认为这是一个很好的DRY方式,因为Gemfile中指定的gem是我在我的应用程序中需要的。我为什么要在app.rb中再次指定需求?所以我将代码更改为:

require 'rubygems'
require 'bundler'
Bundler.require(:default)

Much nicer huh? Not until problem ensues:

好多了?直到问题发生:

Errno::ENOENT at /
No such file or directory - /home/lamnk/.rvm/gems/ruby-1.9.2-head/gems/bundler-1.0.7/lib/bundler/views/index.haml
file: tilt.rb location: read line: 119

Clearly bundler has moved the app's root path to its own. But why is that?

很明显,bundler已经将应用程序的根路径移动到了自己的路径。但那是为什么呢?

1 个解决方案

#1


3  

Old answer:

Take a look at "using the rubygems bundler for your app" on the Engine Yard blog.

在Engine Yard博客上查看“为您的应用程序使用rubygems bundler”。

New answer:

As Lamnk pointed out, that post on Engine Yard is old; so I made a simple app https://github.com/sinetris/sinatra-example-bundler

正如Lamnk所指出的那样,Engine Yard上的帖子已经过时了;所以我制作了一个简单的应用程序https://github.com/sinetris/sinatra-example-bundler

#1


3  

Old answer:

Take a look at "using the rubygems bundler for your app" on the Engine Yard blog.

在Engine Yard博客上查看“为您的应用程序使用rubygems bundler”。

New answer:

As Lamnk pointed out, that post on Engine Yard is old; so I made a simple app https://github.com/sinetris/sinatra-example-bundler

正如Lamnk所指出的那样,Engine Yard上的帖子已经过时了;所以我制作了一个简单的应用程序https://github.com/sinetris/sinatra-example-bundler