Module: Reform::Form::Composition::ClassMethods
- Includes:
- ActiveModel::ClassMethods
- Defined in:
- lib/reform/form/composition.rb
Instance Method Summary collapse
-
#model(main_model, options = {}) ⇒ Object
Same as ActiveModel::model but allows you to define the main model in the composition using
:on
. -
#model_class ⇒ Object
DISCUSS: needed?.
- #property(name, options = {}) ⇒ Object
Methods included from ActiveModel::ClassMethods
Instance Method Details
#model(main_model, options = {}) ⇒ Object
Same as ActiveModel::model but allows you to define the main model in the composition using :on
.
class CoverSongForm < Reform::Form
model :song, on: :cover_song
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/reform/form/composition.rb', line 32 def model(main_model, ={}) super composition_model = [:on] || main_model delegate composition_model => :model # #song => model.song # FIXME: this should just delegate to :model as in FB, and the comp would take care of it internally. delegate [:persisted?, :to_key, :to_param] => composition_model # #to_key => song.to_key alias_method main_model, composition_model # #hit => model.song. end |
#model_class ⇒ Object
DISCUSS: needed?
15 16 17 18 19 20 |
# File 'lib/reform/form/composition.rb', line 15 def model_class # DISCUSS: needed? rpr = representer_class @model_class ||= Class.new(Reform::Composition) do map_from rpr end end |
#property(name, options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/reform/form/composition.rb', line 22 def property(name, ={}) super delegate [:on] => :@model end |