Ruby on rails 如何为一个项目创建多个文件?
在我的团队中,有些人喜欢使用Ruby on rails 如何为一个项目创建多个文件?,ruby-on-rails,ruby,rubygems,bundler,Ruby On Rails,Ruby,Rubygems,Bundler,在我的团队中,有些人喜欢使用pry railsgem,有些人不喜欢 有没有一种方法可以让一个二级GEM文件用于开发,而我不将其提交给git,并且仍然由bundler读取?您可以运行: BUNDLE_GEMFILE=/path/to/another/gemfile bundle install 或在Gemfile中(将与提交的Gemfile.lock产生冲突): 并使用_PRYenv变量填充,以启用PRY 另一种避免Gemfile.lock与Rails应用程序冲突的解决方案: # In Gem
pry rails
gem,有些人不喜欢
有没有一种方法可以让一个二级GEM文件用于开发,而我不将其提交给git,并且仍然由bundler
读取?您可以运行:
BUNDLE_GEMFILE=/path/to/another/gemfile bundle install
或在Gemfile中(将与提交的Gemfile.lock产生冲突):
并使用_PRYenv变量填充,以启用PRY
另一种避免Gemfile.lock与Rails应用程序冲突的解决方案:
# In Gemfile
group :dev_with_pry do
gem 'pry-rails'
end
并将dev\u with_pry添加到RAILS\u GROUPSenv变量中,这将安装gem,但不需要它。根据共享的规范,您可以管理两个gem文件,并根据环境需要使用它们
Gemfile
source 'https://rubygems.org'
gemfiles = [ 'Gemfile1', 'Gemfile2' ]
gemfiles.each do |gemfile|
instance_eval File.read(gemfile)
end
end
现在您可以有两个单独的文件,例如
Gemfile1
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'pry'
然后可以在Gemfile2中添加其他gem
档案2
source 'https://rubygems.org'
https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
希望能有帮助 我不认为这是可能的,但是你可以通过某种方式对git隐藏它。@Gabbar如何对git隐藏它?@Shobhit我想他正在考虑。gitignoreI建议通过环境变量有条件地要求它,而不是有条件地将它包含在Gemfile中。下面的答案有一个大问题:开发人员将不断更新
Gemfile.lock
,并意外地将其检查到源代码管理中@Shobhit解决此gem的具体潜在问题的真正方法是:为所有人在gem文件中包含pry rails
,不喜欢它的人可以在他们的配置文件中使用export DISABLE\u pry\u rails=1
明确禁止它。pry rails已经支持此选择退出,您不需要引入第二个gemfile来选择性地包含/排除此gem。谢谢,这看起来是解决我问题的一个很好的解决方案。这将给gemfile.lock带来一些奇怪的问题,一些开发人员将不得不记住不要提交,正如Tom Lord在上面已经指出的,我添加了另一个解决方案来避免Gemfile.lock冲突
source 'https://rubygems.org'
https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end