Rails:LoadError

编程入门 行业动态 更新时间:2024-10-26 08:30:40
本文介绍了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).

确保您执行以下步骤:

  • 杀死服务器
  • 运行bundle update或bundle install
  • 再次运行服务器
  • Kill server
  • Run bundle update or bundle install
  • Run server again
  • 现在,捆绑程序应该可以让您访问rails控制器中所有active_campaign的类

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

    更多推荐

    Rails:LoadError

    本文发布于:2023-10-16 16:56:46,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1498178.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Rails   LoadError

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!