我想让邦德勒装本地宝石。有别的选择吗?或者我必须将gem文件夹移动到.bundle目录?
除了指定路径(如Jimmy提到的),您还可以通过使用以下配置选项强制Bundler仅为您的环境使用本地gem:
$ bundle config set local.GEM_NAME /path/to/local/git/repository
如果你正在开发两个gem或者一个gem和一个rails应用程序,这是非常有用的。
但是请注意,这只在你已经在使用git的依赖时才有效,例如:
# In Gemfile
gem 'rack', :github => 'rack/rack', :branch => 'master'
# In your terminal
$ bundle config set local.rack ~/Work/git/rack
从文档中可以看到。
你也可以用git引用一个本地gem,如果你碰巧正在使用它的话。
gem 'foo',
:git => '/Path/to/local/git/repo',
:branch => 'my-feature-branch'
然后,如果有变化,我就跑
bundle exec gem uninstall foo
bundle update foo
但我不确定每个人都需要执行这两个步骤。
为了在Rails项目中使用本地gem存储库,请遵循以下步骤:
Check if your gem folder is a git repository (the command is executed in the gem folder) git rev-parse --is-inside-work-tree Getting repository path (the command is executed in the gem folder) git rev-parse --show-toplevel Setting up a local override for the rails application bundle config local.GEM_NAME /path/to/local/git/repository where GEM_NAME is the name of your gem and /path/to/local/git/repository is the output of the command in point 2 In your application Gemfile add the following line: gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master' Running bundle install should give something like this: Using GEM_NAME (0.0.1) from git://github.com/GEM_NAME/GEM_NAME.git (at /path/to/local/git/repository) where GEM_NAME is the name of your gem and /path/to/local/git/repository from point 2 Finally, run bundle list, not gem list and you should see something like this: GEM_NAME (0.0.1 5a68b88) where GEM_NAME is the name of your gem
以下是我观察到的一些重要案例:
Rails 4.0.2
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
Ubuntu 13.10
RubyMine 6.0.3
It seems RubyMine is not showing local gems as an external library. More information about the bug can be found here and here When I am changing something in the local gem, in order to be loaded in the rails application I should stop/start the rails server If I am changing the version of the gem, stopping/starting the Rails server gives me an error. In order to fix it, I am specifying the gem version in the rails application Gemfile like this: gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
你可以用source引用宝石:
来源:'https://source.com', git仓库(:github => 'git/url') 使用本地路径
:path => '…/path/gem_name'。
您可以了解更多关于[Gemfiles和如何使用它们] (https://kolosek.com/rails-bundle-install-and-gemfile)。
推荐文章
- 确定ActiveRecord对象是否为New
- Rails中的OO设计:在哪里放置东西
- 如何在Heroku上重新启动rails服务器?
- respond_to块如何工作?
- 给定一个类,查看实例是否有方法(Ruby)
- rails局部模板中的可选局部变量:如何退出(defined?foo)混乱?
- 在日历应用程序中建模重复事件的最佳方法是什么?
- Ruby Bundle Symbol not found: _SSLv2_client_method (LoadError)
- 如何创建一个私有类方法?
- rails耙任务是否提供对ActiveRecord模型的访问?
- 无法安装pg gem
- 双* (splat)操作符做什么
- 如何使用Ruby on Rails进行HTTP请求?
- (1) libcurl不支持或禁用https协议
- Destroy和Delete的区别