0

I'm import the active_campaign gem into a controller like so (already included in my Gemfile and ran bundle install):

require 'active_campaign' class Website::MyController < ApplicationController def create client = ::ActiveCampaign::Client.new("url","api-key") # ... end end 

I get the following error:

LoadError in Website::MyController#create cannot load such file -- active_campaign

Removing the require 'active_campaign' line

After removing the require line, I now get:

NameError in Website::MyController#create uninitialized constant ActiveCampaign

How can I get this to work?

12
  • i think you have typo instead ::ActiveCampaign::Client.new("url","api-key") use ActiveCampaign::Client.new("url","api-key") Commented Aug 6, 2014 at 12:30
  • Check your load path (output $LOAD_PATH rails console for example) Your gem needs to be located in any directory of your load path, otherwise require will fail if you don't use an absolute path. Commented Aug 6, 2014 at 12:34
  • You don't have to require explicit any gem in controller. Have you tried bundle update ? Commented Aug 6, 2014 at 12:39
  • @kevdev I just see a huge list of directories. How can I tell if it's located in one of those directories or not? (using Ubuntu 14.04) Commented Aug 6, 2014 at 12:41
  • @FilipBartuzi just ran bundle update. Nothing's changed (same error) Commented Aug 6, 2014 at 12:42

1 Answer 1

3

It is rails controller so you don't have explicit require any gems. Bundler does it. Perhaps you can't access ActiveCampaign constant because you added gem after starting a server (so after bundler require all gems and give you access to their classes).

Ensure you do following steps:

  1. Kill server
  2. Run bundle update or bundle install
  3. Run server again

Now bundler should give you access to all active_campaign's classes in rails controllers

Sign up to request clarification or add additional context in comments.

1 Comment

That was it! I wrote a note on my beside: always restart the server after a bundle install!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.