APIs & Integrations

altjx
Contributor

hubspot-api-client not working in Rails?

I am trying to use the Hubspot API Ruby gem located here https://github.com/HubSpot/hubspot-api-ruby#installation, but I am having issues with Ruby on Rails.

 

For all of my other gems, I can just simply add the gem in the Gemfile and it works within the application, but not this case and I cannot figure out why.

 

For example, here's what I have in my Gemfile:

 

# HubSpot API Client
gem 'hubspot-api-client'


I have ran `bundle install` and it installed successfully, but I still can't use that gem. If I load the gem via the `irb` console, then it works just fine.

Here's what I mean:

 

Using IRB

root@8af3866a29c8:/myapp# irb
irb(main):001:0> require 'hubspot-api-client'
=> true
irb(main):002:0> Hubspot
=> Hubspot


Using Rails Console

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>


Why does this happen and how do I fix this?

0 Upvotes
7 Replies 7
creeder
Member

hubspot-api-client not working in Rails?

Hey, sorry to hear that you're still struggling with this!

Idk what version you're running or what changes you made to the default setup, but I just ran created a fresh app like so:

rails new test_app
cd test_app
bundle install
rails webpacker:install

which yields a functioning base app.

 

Then I added

gem 'hubspot-api-client'

to my Gemfile and then issued another

bundle install

 

And right away if I launch into the rails console, I get the expected behavior.

Rails automatically loads the gems in your Gemfile.

 

Just out of curiousity, if you do a fresh install like this (with no other changes), do you still have the same issue?

altjx
Contributor

hubspot-api-client not working in Rails?

Yeah unfortunately I've tried avoiding the "require" statement and tried including it, and both options seem to lead to the same thing still.

0 Upvotes
GaryElliott
Member

hubspot-api-client not working in Rails?

I think your issue might be related to requiring the gem in console. This article might help you out... https://www.ombulabs.com/blog/rails/ruby/how-to-use-any-gem-in-production-console.html

altjx
Contributor

hubspot-api-client not working in Rails?

Lol!!

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

hubspot-api-client not working in Rails?

@altjx 

2 things

I am a fan of the music of alt j

I took a class on ruby on rails about 15 years ago. (I am old) so I am of no help in answering this, but I can attempt to summon the Ruby folks of the Community

@GaryElliott, @ivandhalluin , @creeder , @okodoon can you all help here?

(please imagine that was a scene from Lord of the Rings)

 

altjx
Contributor

hubspot-api-client not working in Rails?

Haha thanks @dennisedson! Hoping they can provide some help. Over the last few hours I've been writing my own library to interact with the API over GET/POST requests and would prefer to avoid duplicating work lol.

dennisedson
HubSpot Product Team
HubSpot Product Team

hubspot-api-client not working in Rails?

Just so you know, I now know you exist and you will be summoned in the future 😉

(now imagine evil laughter)