Rails:LoadError-无法加载此类文件(需要gem) [英] Rails: LoadError - Cannot load such file (requiring a gem)
问题描述
我将 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).
确保您执行以下步骤:
- 杀死服务器
- 运行
bundle update
或bundle install
- 再次运行服务器
- Kill server
- Run
bundle update
orbundle install
- Run server again
现在,捆绑程序应该可以让您访问rails控制器中所有active_campaign
的类
Now bundler should give you access to all active_campaign
's classes in rails controllers
这篇关于Rails:LoadError-无法加载此类文件(需要gem)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!