Ruby on rails Rails 4:从内到外了解bundler
我正在开发一个Rails4应用程序,我将所有gems本地化到:vendor/gems文件夹 完成此操作后,我的应用程序中有一个名为:.bundle的文件夹,其中包含配置文件Ruby on rails Rails 4:从内到外了解bundler,ruby-on-rails,bundler,Ruby On Rails,Bundler,我正在开发一个Rails4应用程序,我将所有gems本地化到:vendor/gems文件夹 完成此操作后,我的应用程序中有一个名为:.bundle的文件夹,其中包含配置文件 # Content inside config file --- BUNDLE_PATH: vendor/gems BUNDLE_DISABLE_SHARED_GEMS: '1' 后来,我意识到,我不想本地化Gemfile中的每个gem。我希望我的应用程序使用系统中可以定义的少量gem,以及供应商/gems文件夹中的少量g
# Content inside config file
---
BUNDLE_PATH: vendor/gems
BUNDLE_DISABLE_SHARED_GEMS: '1'
后来,我意识到,我不想本地化Gemfile中的每个gem。我希望我的应用程序使用系统中可以定义的少量gem,以及供应商/gems文件夹中的少量gem
要做到这一点:
我删除了.bundle文件夹
已删除Gemfile.lock
打开Gemfile并进行以下修改并运行bundle安装:
我明白了:
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Installing mysql2 0.3.17
Using rails 4.1.8 from source at vendor/gems
Using uglifier 2.5.3 from source at vendor/gems
Using bundler 1.6.5
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
当我查看Gemfile.lock时,我看到:
PATH
remote: vendor/gems
specs:
uglifier (2.5.3)
PATH
remote: vendor/gems
specs:
rails (4.1.8)
GEM
remote: https://rubygems.org/
specs:
mysql2 (0.3.17)
PLATFORMS
ruby
DEPENDENCIES
mysql2 (= 0.3.17)
rails (= 4.1.8)!
uglifier (= 2.5.3)!
{PATH_TO_APP} $bundle show mysql2
-> /home/pp/.rvm/gems/ruby-1.9.3-p547/gems/mysql2-0.3.17
我注意到rails=4.1.8&uglifier=2.5.3无法找到合适的路径
为了改变这一点,我再次打开了我的GEM文件,并将代码更改为:
source 'https://rubygems.org'
gem 'rails', '4.1.8', path: "vendor/gems/ruby/1.9.1"
gem 'mysql2', '0.3.17' # Use mysql as the database for Active Record
gem 'uglifier', '2.5.3', path: "vendor/gems/ruby/1.9.1" # Use Uglifier as compressor for JavaScript assets
当我再次尝试运行bundle安装时,我发现以下跟踪:
activerecord at /home/pp/Workspace/MyProject/vendor/gems/ruby/1.9.1/specifications did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
["README.rdoc"] are not files
Using activerecord 4.1.8 from source at vendor/gems/ruby/1.9.1
Using bundler 1.6.5
Using execjs 2.2.2 from source at vendor/gems/ruby/1.9.1
Using hike 1.2.3 from source at vendor/gems/ruby/1.9.1
Using multi_json 1.10.1 from source at vendor/gems/ruby/1.9.1
mysql2 at /home/pp/Workspace/MyProject/vendor/gems/ruby/1.9.1/specifications did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
If you need to use this package without installing it from a gem repository, please contact seniorlopez@gmail.com and ask them to modify their .gemspec so it can work with `gem build`.
The validation message from Rubygems was:
["ext/mysql2/extconf.rb"] are not files
Using mysql2 0.3.17 from source at vendor/gems/ruby/1.9.1
并从Gemfile.lock进行跟踪
这里发生了三件事:
依赖项仍然不满足。
mysql2,而不是从系统中挑选,bundler是从供应商/gems中挑选的
activerecord和其他gem的警告消息
我被卡住了,想知道,实现这种行为的最佳方式是什么。我是遗漏了什么还是遵循了正确的方法?为什么要将所有gem本地化到供应商文件夹中?我建议创建自己的。并更改Gem文件中的源路径,我希望它能工作。感谢@Lareb提供的解决方案。然而,由于一些限制,我不能选择拥有自己的GemServer。第一:因为,GemServer需要自己的端口,例如localhost:9292。即使我们设法在所需的端口上运行它,稍后,托管团队内部也可以阻止此端口。我在这里看到过类似的问题。第二个限制:有一些gem是所有应用程序(如mysql2等)所共有的。这些gem位于所有应用程序都可以访问的共享路径上,因此我可能必须在Gemfile中定义各种源。我知道这不是一个大挑战,可以找到解决办法。但是现在你已经看到了这一点,你的看法是什么?
source 'https://rubygems.org'
gem 'rails', '4.1.8', path: "vendor/gems/ruby/1.9.1"
gem 'mysql2', '0.3.17' # Use mysql as the database for Active Record
gem 'uglifier', '2.5.3', path: "vendor/gems/ruby/1.9.1" # Use Uglifier as compressor for JavaScript assets
activerecord at /home/pp/Workspace/MyProject/vendor/gems/ruby/1.9.1/specifications did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
["README.rdoc"] are not files
Using activerecord 4.1.8 from source at vendor/gems/ruby/1.9.1
Using bundler 1.6.5
Using execjs 2.2.2 from source at vendor/gems/ruby/1.9.1
Using hike 1.2.3 from source at vendor/gems/ruby/1.9.1
Using multi_json 1.10.1 from source at vendor/gems/ruby/1.9.1
mysql2 at /home/pp/Workspace/MyProject/vendor/gems/ruby/1.9.1/specifications did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
If you need to use this package without installing it from a gem repository, please contact seniorlopez@gmail.com and ask them to modify their .gemspec so it can work with `gem build`.
The validation message from Rubygems was:
["ext/mysql2/extconf.rb"] are not files
Using mysql2 0.3.17 from source at vendor/gems/ruby/1.9.1
PATH
remote: vendor/gems/ruby/1.9.1
specs:
actionmailer (4.1.8)
actionpack (= 4.1.8)
actionview (= 4.1.8)
mail (~> 2.5, >= 2.5.4)
actionpack (4.1.8)
actionview (= 4.1.8)
activesupport (= 4.1.8)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionview (4.1.8)
activesupport (= 4.1.8)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.8)
activesupport (= 4.1.8)
builder (~> 3.1)
activerecord (4.1.8)
activemodel (= 4.1.8)
activesupport (= 4.1.8)
arel (~> 5.0.0)
activesupport (4.1.8)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
mysql2 (0.3.17)
....
PATH
remote: vendor/gems/ruby/1.9.1
specs:
rails (4.1.8)
actionmailer (= 4.1.8)
actionpack (= 4.1.8)
actionview (= 4.1.8)
activemodel (= 4.1.8)
activerecord (= 4.1.8)
activesupport (= 4.1.8)
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.8)
sprockets-rails (~> 2.0)
GEM
remote: https://rubygems.org/
specs:
....
PLATFORMS
ruby
DEPENDENCIES
mysql2 (= 0.3.17)
rails (= 4.1.8)!
uglifier (= 2.5.3)!