Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在一个模块中使用多个_Ruby On Rails - Fatal编程技术网

Ruby on rails 在一个模块中使用多个

Ruby on rails 在一个模块中使用多个,ruby-on-rails,Ruby On Rails,我有一个模型评估,有很多模型标签,通过评估标签 我需要在此模块中添加此关系,但我不知道如何才能做到这一点 class Evaluation < ApplicationRecord belongs_to :user belongs_to :teacher belongs_to :school belongs_to :subject has_many :evaluation_tags has_many :tags, through: :eval

我有一个模型评估,有很多模型标签,通过评估标签

我需要在此模块中添加此关系,但我不知道如何才能做到这一点

class Evaluation < ApplicationRecord
    belongs_to :user
    belongs_to :teacher
    belongs_to :school
    belongs_to :subject

    has_many :evaluation_tags
    has_many :tags, through: :evaluation_tags

    accepts_nested_attributes_for :evaluation_tags

    validates :teacher_id, presence: true
    validates :subject_id, presence: true
    validates :school_id, presence: true
    validates :user_id, presence: true
    validates :rating, presence: true
end

module Wizard
  module Evaluation
    STEPS = %w(step1 step2 step3).freeze

    class Base
      include ActiveModel::Model
      attr_accessor :evaluation

      delegate *::Evaluation.attribute_names.map { |attr| [attr, "#{attr}="] }.flatten, to: :evaluation

      def initialize(evaluation_attributes)
        @evaluation = ::Evaluation.new(evaluation_attributes)
      end
    end

    class Step1 < Base
      validates :teacher_id, presence: true
    end

    class Step2 < Step1
      validates :subject_id, presence: true
    end

    class Step3 < Step2
      validates :school, presence: true
      validates :user, presence: true
      validates :rating, presence: true
    end
  end
end
当我访问step3页面时,会出现此错误

未定义的方法“tag_id”

有人能帮我吗?

我想你可以这样使用:

module Wizard
  module Evaluation
    extend ActiveSupport::Concern

    included do
      has_many :tags, through: :evaluation_tags
    end
  end
end
那么你的课程需要包括:

class Evaluation
  include Wizard::Evaluation
end

为什么不将模块包括在评估中?请给我看一下好吗?谢谢,我需要在模型中包括include Wizard::Evaluation?未定义的错误方法“tag_id”继续