Module: Reform::Form::Composition::ClassMethods

Defined in:
lib/reform/form/composition.rb

Instance Method Summary collapse

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


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/reform/form/composition.rb', line 30

def model(main_model, options={})
  super

  composition_model = options[: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_classObject

include Reform::Form::ActiveModel::ClassMethods # ::model.



15
16
17
# File 'lib/reform/form/composition.rb', line 15

def model_class # DISCUSS: needed?
  @model_class ||= Reform::Composition.from(representer_class)
end

#property(name, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/reform/form/composition.rb', line 19

def property(name, options={})
  super.tap do |definition|
    delegate options[:on] => :@model # form.band -> composition.band
  end
end