Method: Reform::Form::Composition::ClassMethods#model

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

#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
42
43
44
45
# File 'lib/reform/form/composition.rb', line 30

def model(main_model, options={})
  super

  composition_model = options[:on] || main_model

  handle_deprecated_model_accessor(composition_model)  unless options[:skip_accessors] # TODO: remove in 1.2.

  # FIXME: this should just delegate to :model as in FB, and the comp would take care of it internally.
  [:persisted?, :to_key, :to_param].each do |method|
    define_method method do
      model[composition_model].send(method)
    end
  end

  alias_method main_model, composition_model # #hit => model.song. # TODO: remove in 1.2.
end