【问题标题】:Why does Bundler.require load the wrong path?为什么 Bundler.require 加载错误的路径?
【发布时间】:2010-11-22 16:06:27
【问题描述】:

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

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

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

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

好多了啊?直到问题出现:

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

显然,bundler 已将应用程序的根路径移至其自己的路径。但这是为什么呢?

【问题讨论】:

  • 您可以使用“set :views, File.dirname(FILE) + '/view'”更改视图路径

标签: ruby sinatra bundler


【解决方案1】:

旧答案:

查看 Engine Yard 博客上的 "using the rubygems bundler for your app"

新答案:

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

【讨论】:

  • 这篇文章很老了,require_env 已经不存在了,它不能解释我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
  • 2017-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-13
相关资源
最近更新 更多