简体   繁体   English

了解Gemfile(Rails):如果已经包含“宝石'mongo'”,则不需要“需要mongo”吗?

[英]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.

相关问题 不需要mongo gem - Cannot require mongo gem 如何在Rails gemfile中要求特定的gem版本? - How to require a specific gem version in rails gemfile? 如何在.irbrc中要求gem而不需要将其添加到Rails Gemfile中? - How to require a gem in .irbrc without needing to also add it to a Rails Gemfile? 为什么在 Gemfile 中包含 gem 可以解决 railtie 问题,即使 Gemfile.lock 中已包含相同的 gem? - Why does including a gem in Gemfile resolve a railtie issue, even though this same gem is already included in Gemfile.lock? 如何在 Mac 上使用 Sqlite3 运行 rails? 我收到“ gem 未加载”,但它已包含在 Gemfile 中 - How can I run rails with Sqlite3 on Mac? I'm getting " gem is not loaded" but it was included on Gemfile Rails3.1:这是在Gemfile中要求本地开发的gem / engine的正确方法吗? - Rails3.1: Is this the right way to require my locally being developed gem/engine in the Gemfile? Gemfile在除一种环境外的所有环境中都需要gem - Gemfile require gem in all environments except one 了解Ruby on Rails gemfile中的组 - understanding groups in ruby on rails gemfile Rails:您已经激活了 rake 10.3.1,但是您的 Gemfile 需要 rake 10.2.2 (Gem::LoadError) - Rails: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2 (Gem::LoadError) 为什么即使我的Rails引擎位于Gemfile中并配置了require_paths,我的Rails引擎仍需要我提出要求(不同于典型的gem)? - Why does my Rails engine need me to require it (unlike a typical gem) even if it's in the Gemfile and has require_paths configured?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM