RoR: NameError: Uninitialized constant (Service)


this is my first question in SO :)
I am new to RoR and I am trying to understand PINGOWebApp, which you can find here https://github.com/PingoUPB/PINGOWebApp . They asked their question model (app / models / question.rb) in different types of questions in app / services / (for example, number_question.rb, text_question.rb), all inherited from the application / services / generic _question.rb:

class GenericQuestion < Delegator

  def initialize(question)
    super
    @question = question
  end

  def __getobj__ # required
    @question
  end

  def __setobj__(obj)
      @question = obj # change delegation object
  end

  def to_model
    @question.to_model
  end

  def has_settings?
    false
  end

  def add_setting(key, value)
    @question.settings ||= {}
    @question.settings[key.to_s] = value.to_s
  end

  def self.model_name
    Question.model_name
  end

  def self.reflect_on_association arg
    Question.reflect_on_association arg
  end

  alias_method :question, :__getobj__ # reader for survey

end

Here are my first questions:
1) Since there is no service generator, they had to create all the ruby ​​files in the application / service / manually, right? Or what other ways exist?

2) I forked the project and added another service manually, called dragdrop_question.rb, and integrated it into question_controller.rb:

class QuestionsController < ApplicationController
...
  def new
    @question_single = SingleChoiceQuestion.new.tap { |q| q.question_options.build }
    @question_multi = MultipleChoiceQuestion.new.tap { |q| q.question_options.build }
    @question_text = TextQuestion.new
    @question_number = NumberQuestion.new  #refactor this maybe?
    @question_dragdrop = DragDropQuestion.new.tap { |q| q.answer_pairs.build }
  end
...
end

. NameError /questions/new uninitialized constant QuestionsController:: DragDropQuestion.

require_dependency "app/services/dragdrop_question.rb"

question_controller.rb , . , ?


, , ---.

+4
1

, DragDropQuestion, drag_drop_question.rb.

+7

All Articles