Rails:LoadError-无法加载此类文件(需要gem) [英] Rails: LoadError - Cannot load such file (requiring a gem)

查看:93
本文介绍了Rails:LoadError-无法加载此类文件(需要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).

确保您执行以下步骤:

  1. 杀死服务器
  2. 运行bundle updatebundle install
  3. 再次运行服务器
  1. Kill server
  2. Run bundle update or bundle install
  3. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆