[英]Understanding Gemfile (Rails): “require mongo” unnecessary if “gem 'mongo'” is already included?
This is our Gemfile. 这是我们的Gemfile。
Is the line require mongo redundant since gem 'mongo' is already included? 该行是否要求mongo冗余,因为已经包含gem'mongo' ?
If not, what is the purpose of require mongo ? 如果不是,那么require mongo的目的是什么?
We're on Rails 3. 我们在轨道上3。
Thanks! 谢谢!
source 'http://rubygems.org'
require 'rubygems'
require 'mongo'
gem 'rails', '3.0.6'
gem 'mongo'
gem 'mongo_mapper'
gem 'fastercsv'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3'
gem 'mysql'
gem 'whois'
You shouldn't put require
statements in your Gemfile. 您不应该在Gemfile中放入
require
语句。 This is also true for the require 'rubygems'
on the line before. 这对于之前的行中
require 'rubygems'
也是如此。
What require does, is what it always does: load the gem. require要做的就是永远做:加载gem。 The Gemfile is loaded when you run
bundle install
. 运行
bundle install
时将加载Gemfile。 If you try to load a gem before bundle install
has run, the gem might not be installed yet. 如果您在运行
bundle install
之前尝试加载gem,则该gem可能尚未安装。
Gems specified in your Gemfile are required by Rails by default too, by the way. 顺便说一下,默认情况下,Rails也需要在Gemfile中指定的宝石。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.