我将 active_campaign gem 导入到这样的控制器中(已经包含在我的Gemfile中并运行bundle install):
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我收到以下错误:
网站:: MyController#create中的LoadError 无法加载此类文件-active_campaign
LoadError in Website::MyController#create cannot load such file -- active_campaign
删除require 'active_campaign'行
删除需求行后,我得到:
Removing the require 'active_campaign' line
After removing the require line, I now get:
Website :: MyController#create中的NameError未创建常量ActiveCampaign
NameError in Website::MyController#create uninitialized constant ActiveCampaign
如何使它正常工作?
推荐答案它是rails控制器,因此您没有显式的require任何宝石. Bundler做到了. 也许您无法访问ActiveCampaign常量,因为您在启动服务器后添加了gem(因此,在bundler之后,需要所有gem并允许您访问其类).
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).
确保您执行以下步骤:
现在,捆绑程序应该可以让您访问rails控制器中所有active_campaign的类
Now bundler should give you access to all active_campaign's classes in rails controllers
更多推荐
Rails:LoadError
发布评论