我正在尝试使用位于此处的 Hubspot API Ruby gem https://github.com/HubSpot/hubspot-api-ruby#installation,但我在使用 Ruby on Rails 时遇到问题。
对于我的所有其他 gem,我只需将 gem 添加到 Gemfile 中,它就可以在应用程序中工作,但在这种情况下不行,我不明白为什么。
例如,这是我的 Gemfile 中的内容:
# HubSpot API Client
gem 'hubspot-api-client'
我已经运行了
bundle install
并且安装成功,但我仍然无法使用那个gem。如果我通过 irb
控制台加载 gem,那么它就可以正常工作。
这就是我的意思:
使用IRB
root@8af3866a29c8:/myapp# irb
irb(main):001:0> require 'hubspot-api-client'
=> true
irb(main):002:0> Hubspot
=> Hubspot
使用 Rails 控制台
root@8af3866a29c8:/myapp# rails c
Running via Spring preloader in process 6589
Loading development environment (Rails 5.2.4)
irb(main):001:0> require 'hubspot-api-client'
Traceback (most recent call last):
1: from (irb):1
LoadError (cannot load such file -- hubspot-api-client)
irb(main):001:0> Hubspot
Traceback (most recent call last):
1: from (irb):1
NameError (uninitialized constant Hubspot)
irb(main):002:0>
为什么会发生这种情况以及如何解决这个问题?
您必须在 Gemfile 中包含 gem 'hubspot-api-client'。 Rails 仅加载 Gemfile 中指定的 gem。