我想让邦德勒装本地宝石。有别的选择吗?或者我必须将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)。
推荐文章
- Rails new vs create
- Rails has_many的别名
- 如何记录Ruby代码?
- Ruby:包含的反义词是什么?Ruby数组?
- 想要在Rails中找到没有关联记录的记录
- helper和helper_method做什么?
- 如何回滚只是一个步骤使用耙db:迁移
- 在Ruby中,proc和lambda有什么区别?
- 如何传递参数到一个Rake任务与环境在Rails?
- 获取当前正在执行的方法的名称
- 如何在Rails中计算相对时间?
- 如何在Rails迁移中将可空列更改为不可空列?
- 在Ruby中使用范围填充数组的正确方法
- “for”和“each”在Ruby中
- Ruby on Rails -从CSV文件导入数据