Вложенные модели в Rails

Генератор моделей

rails g model Quiz/Question

# create app/models/quiz/question.rb
# create app/models/quiz.rb

Модели

# app/models/quiz.rb

module Quiz
  def self.table_name_prefix
    'quiz_'
  end
end
# app/models/quiz/question.rb

class Quiz::Question < ApplicationRecord
  has_many :answer_variants, inverse_of: :question, dependent: :destroy
end

# Table name: quiz_questions
# app/models/quiz/answer_variant.rb

class Quiz::AnswerVariant < ApplicationRecord
  belongs_to :question, class_name: "Quiz::Question", counter_cache: true
end

# Table name: quiz_answer_variants

Переводы

ru:
  activerecord:
    models:
      quiz/question:
        one:   Вопрос
        few:   Вопроса
        many:  Вопросов
        other: Вопросы
        zero:  Вопросов

    attributes:
      quiz/question:

Генератор ActiveAdmin

rails g active_admin:resource Quiz/Question
Редактировать