我的控制器中有以下内容:
class SurveysController < ApplicationController
def index
survey_provider = FluidSurveysProviders::SurveyProvider.new
contact_lists = survey_provider.get_lists()
@survey = Survey.new(contact_lists)
end
我收到了这个错误:
NameError in SurveysController#index
uninitialized constant SurveysController::FluidSurveysProviders
请原谅我的Rails noobiness,我相信我在这里遗漏了一些重要的东西。但在我看来,我试图用这一行“初始化”常量:
survey_provider = FluidSurveysProviders::SurveyProvider.new
但这是因为没有初始化而抛出错误的同一行。我应该在哪里“初始化”提供者?
答案 0 :(得分:1)
一旦require fluid_surveys_providers
(或类似),请执行此操作:
include FluidSurveysProviders
答案 1 :(得分:0)
确保SurveyProvider包含FluidSurveysProviders模块。它可能看起来像这样
module FluidSurveysProviders
class SurveyProvider
...
end
end
如果它的ActiveRecord对象试试这个
class FluidSurveysProviders::SurveyProvider < ActiveRecord::Base
...
end