I'm doing a tutorial on authentication and came across the following line for gemfile
. What is the use of require
here?
gem 'google-api-client', require: 'google/api_client'
I understand require
in Javascript, but in Rails I thought the gemfile is for installing gems, and once they are installed they can be used in the application, and thats all there is to it... so I'm not sure why I would use require
.
I'm particularely interested because after adding this line and starting the server, I ran into an error.
Error:
/usr/local/rvm/gems/ruby-2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require': cannot load such file -- google/api_client (LoadError)
Temporary solution: I've commented out the require:
part and the error is prevented. But maybe this is not ideal.
So understanding the use of require
would help very much in troubleshooting this.
I read other articles on SO, but they discuss specifics like require => nil
and require => false
, which I think is a little different from my question.
- Bunder: What does :require => nil in Gemfile mean?
- Bundler: What does :require => false in a Gemfile mean?
Can anyone share some incite?
UPDATE
I later found this which explains it well: When do you need a require in a rails Gemfile?
If you omit the :require option, by default Bundler will attempt to require the gem by using the standard name-to-file conversion rule:
This works well if the gem author has followed the standard conventions. But in some cases, for a variety of reasons, this doesn't happen.