Class: Reform::Form::Populator::IfEmpty
- Inherits:
-
Reform::Form::Populator
- Object
- Reform::Form::Populator
- Reform::Form::Populator::IfEmpty
- Defined in:
- lib/reform/form/populator.rb
Overview
Populator
Instance Method Summary collapse
Methods inherited from Reform::Form::Populator
Constructor Details
This class inherits a constructor from Reform::Form::Populator
Instance Method Details
#call!(options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/reform/form/populator.rb', line 55 def call!() binding, twin, index, fragment = [:binding], [:model], [:index], [:fragment] # TODO: remove once we drop 2.0. form = [:represented] if binding.array? item = twin.original[index] and return item new_index = [index, twin.count].min # prevents nil items with initially empty/smaller collections and :skip_if's. # this means the fragment index and populated nested form index might be different. twin.insert(new_index, run!(form, fragment, )) # form.songs.insert(Song.new) else return if twin form.send(binding.setter, run!(form, fragment, )) # form.artist=(Artist.new) end end |