在活动存储Rails 5.2中使用composed_of

时间:2019-04-03 14:29:01

标签: ruby-on-rails rails-activestorage

我正在对要传递活动存储对象的模型使用composited_of,但是它设置为nil

composed_of :constitutive_act,
    class_name: 'ConstitutiveAct',
    allow_nil: false,
    mapping: [
      ['constitutive_act_person_name', 'person_name'],
      ['constitutive_act_number', 'number'],
      ['constitutive_act_date', 'date'],
      ['constitutive_act_document', 'document'],
    ]
class ConstitutiveAct
  attr_accessor(
    :person_name,
    :number,
    :date,
    :document
  )
  def initialize(person_name, number, date, document)
    @person_name = person_name
    @number = number
    @date = date
    @document = document
  end

constitutive_act.constitutive_act.document

返回nil,但是存在constitutive_act_document属性并进行调整

0 个答案:

没有答案