我正在我的模型中创建一个虚拟属性:
def entities
@entities = Array.new()
@entities.push(self.contact.name)
@entities.push(self.contact.partner.name) if self.contact.partner
@entities.push('Joint') if self.contact.partner
@entities
end
然后在我的表单中,我试图从嵌套数组中使用这个数组。我正在使用简单的形式,所以它看起来像这样
<%= f.input :ownership, collection: :entities, :include_blank => false, :label => false %>
然而,这给了我一个错误:
undefined method `to_a' for :entities:Symbol
如果我创建了一个数组,我不明白为什么它不呈现为一个数组。我错过了什么?