reform
reform copied to clipboard
Support for nested forms with custom models
Let's say you have a parent form, which wants to display a nested form - if your model already has a has_many
association declared, reform will discover that and will use a nested form for that association. This is great, but what if you want to use custom models in that nested form?
I've tried the following:
class BuyerForm
collection :rates, form: RateForm
end
class RateForm
model CurrentRate
end
but that will just populate the rates
collection with RateForm
s whose models will be instances of Rate
rather than CurrentRate
.
In any case, I've come up with this, which I think mostly achieves what I wanted to achieve. I feel however that it should be possible to define what model the child form should use via a call to model
.
Have a look at this repository: https://github.com/jasiek/evil_twin/commit/b36290b98fa5645cc5f0c54b6f4d434f396e8d1d