I had my Reform form working with one nested model, but I need that model to contain another nested model. A tutorial has_many steps, a step has_many images. Here's my attempt:
class TutorialForm < Reform::Form
collection :steps, populator: :step_populator! do
property :title
property :body
validates :title, presence: true
validates :body, presence: true
collection :images, populator: :image_populator! do
property :image
validates :image, presence: true
end
end
def step_populator!(collection:, index:, **)
if (item = collection[index])
item
else
collection.insert(index, Step.new)
end
end
def image_populator!(collection:, index:, **)
if (item = collection[index])
item
else
collection.insert(index, Image.new)
end
end
end
Is this totally wrong? It's not working at the moment.
I had my Reform form working with one nested model, but I need that model to contain another nested model. A tutorial has_many steps, a step has_many images. Here's my attempt:
Is this totally wrong? It's not working at the moment.