私は認証に関するチュートリアルを行い、gemfile
の次の行を見つけました。ここでrequire
の使用は何ですか?`require:`はRailsのgemfileで何を意味しますか?
gem 'google-api-client', require: 'google/api_client'
私はJavaScriptでrequire
を理解しますが、Railsの中で、私はgemfileは宝石を取り付けるためのもので、それらがインストールされた後は、アプリケーションで使用することができ、かつそこにあるすべてのthatsと思いましたそれで...なぜ私はrequire
を使うのか分かりません。
この行を追加してサーバーを起動した後、私はエラーに遭遇したので、特に興味があります。
エラー:
/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)
一時的な解決策:私はrequire:
一部をコメントアウトしましたし、エラーを防止することができます。しかし、これは理想的ではないかもしれません。
require
の使用を理解することは、このトラブルシューティングに非常に役立ちます。
私は他の記事を読んでいますが、require => nil
とrequire => false
のような詳細については議論していますが、これは私の質問とは少し異なると思います。
- Bunder: What does :require => nil in Gemfile mean?
- Bundler: What does :require => false in a Gemfile mean?
誰もがいくつかのINCITEを共有することはできますか?
UPDATE
私は後でそれをうまく説明している本が見つかりました: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.
宝石を使用する関連モデルに 'require ..'を追加し、その部分を宝石ファイルに含めないようにしてください。 –
通常、このエラーは 'google-api-client'宝石のライブラリフォルダに' google/api_client'ファイルがないことを意味します.bashで手動でチェックしてください: 'file $(bundle show google-api-client)/ lib/google/api_client' –
私は実際に 'api_client'ディレクトリに'/usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.5/lib/google/api_client'という名前でcdできます。それは間違った場所で探しているでしょうか? –