Rails: LoadError - Cannot load such file (requiring a gem)

核能气质少年 提交于 2019-12-10 12:16:02

问题


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:

  1. Kill server
  2. Run bundle update or bundle install
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!