Rails Gemfile:在开发中使用一行,在生产中使用另一行 [英] Rails Gemfile: use one line in development, another in production
问题描述
Rails是否可以在生产环境中加载Unicorn gem?现在,我们的解决方案是在本地运行应用程序时注释掉Unicorn Gem,并在推送到Heroku时取消注释该宝石。
我们在Rails 3.2.12上。
Gemfile:
source'http://rubygems.org '
gem'rails','3.2.12'
gem'jquery-rails'
##======= ================================================== ================================
#
##======= ================================================== ================================
gem'mongo'
gem'mongo_mapper'
gem'plucky'
gem'bson_ext'
gem'bson'
gem'newrelic_rpm'
gem'rpm_contrib'
#Gems仅用于资产,默认情况下不需要生产环境中的
#。
group:assets do
gem'sass-rails','〜> 3.2.3'
gem'咖啡栏','〜> 3.2.1'
gem'uglifier','> = 1.0.3'
结束
感谢!
是否有可能让Rails仅加载Unicorn gem在生产?
现在,我们的解决方案是在本地运行
应用程序时注释掉Unicorn gem,并在推送到Heroku时取消注释该宝石。
是的,通过使用 Gemfile
中的组是可能的。更新您的 Gemfile
,如生产
中的独角兽
只有:
#Gemfile
组:生产do
gem'独角兽'
结束
自 WEBrick
是rails的默认Web服务器应用程序,您不需要为开发
组指定任何内容。
在 Gemfile
更新后仍然会运行 bundle install
安装生产宝石。这绝对是一件好事,因为您希望确保您计划在生产中使用的宝石能够在项目的开发阶段与您的应用程序正常工作。
跳过生产
组宝石的安装:
捆绑安装 - 无需生产
需要注意的一点关于 - 没有生产
选项是后续调用捆绑包安装
和捆绑包更新
也将跳过安装和更新生产宝石。要禁用此功能,您需要从 app_root / .bundle / config
中删除 BUNDLE_WITHOUT:production
行:
#app_root / .bundle / config
BUNDLE_WITHOUT:制作
We run Unicorn on Heroku in production but use Webrick in development on a local machine. We are unable to install Unicorn on the local machine.
Is it possible to have Rails load the Unicorn gem only in production? Right now, our solution is to comment out the Unicorn gem when running the app locally and uncomment the gem when pushing to Heroku.
We're on Rails 3.2.12.
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.2.12'
gem 'jquery-rails'
# # =========================================================================================
#
# #=========================================================================================
gem 'mongo'
gem 'mongo_mapper'
gem 'plucky'
gem 'bson_ext'
gem 'bson'
gem 'newrelic_rpm'
gem 'rpm_contrib'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
Thanks!
Is it possible to have Rails load the Unicorn gem only in production? Right now, our solution is to comment out the Unicorn gem when running the app locally and uncomment the gem when pushing to Heroku.
Yes, it is possible by the use of groups in Gemfile
. Update your Gemfile
like follows for the unicorn
gem in production
only:
# Gemfile
group :production do
gem 'unicorn'
end
Since WEBrick
is the default web server for rails apps, you wouldn't need to specify anything for development
group.
Running bundle install
after the Gemfile
update will still install the production gems. This is definitely a good thing to do as you want to make sure the gems you are planning to use in production work correctly with your application from the development phase of project.
To skip installation of production
group gems:
bundle install --without production
A point to be noted about the --without production
option is that the subsequent calls to bundle install
and bundle update
are also going to skip installing and updating production gems. To disable this you'd need to remove the lineBUNDLE_WITHOUT: production
from your app_root/.bundle/config
:
# app_root/.bundle/config
BUNDLE_WITHOUT: production
这篇关于Rails Gemfile:在开发中使用一行,在生产中使用另一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!