I am creating a virtual attribute in my model:
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
Then in my form I’m trying to use this array from a nested array. I’m using simple form so it looks like this
<%= f.input :ownership, collection: :entities, :include_blank => false, :label => false %>
However this gives me an error:
undefined method `to_a' for :entities:Symbol
If I have created an array, I don’t understand why it isn’t rendering as an array. What am I missing?
You can’t use
:entitiesas the collection:That doesn’t work. The error indicates that Simple Form is attempting to convert the argument
:entitiesto an array, which is causing an error.You need to give it an actual collection: