问题
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?
回答1:
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:
- Kill server
- Run
bundle update
orbundle install
- Run server again
Now bundler should give you access to all active_campaign
's classes in rails controllers
来源:https://stackoverflow.com/questions/25160377/rails-loaderror-cannot-load-such-file-requiring-a-gem