Module: Reform::Form::ActiveModel::ClassMethods

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

this module is only meant to extend (not include). # DISCUSS: is this a sustainable concept?



23
24
25
26
27
28
# File 'lib/reform/form/active_model.rb', line 23

def self.extended(base)
  base.class_eval do
    extend Uber::InheritableAttribute
    inheritable_attr :model_options
  end
end

Instance Method Details

#model(main_model, options = {}) ⇒ Object

Set a model name for this form if the infered is wrong.

class CoverSongForm < Reform::Form
  model :song

or we can setup a isolated namespace model ( which defined in isolated rails egine )

class CoverSongForm < Reform::Form
  model "api/v1/song", namespace: "api"


40
41
42
# File 'lib/reform/form/active_model.rb', line 40

def model(main_model, options={})
  self.model_options = [main_model, options]
end

#model_nameObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/reform/form/active_model.rb', line 44

def model_name
  if model_options
    form_name = model_options.first.to_s.camelize
    namespace = model_options.last[:namespace].present? ? model_options.last[:namespace].to_s.camelize.constantize : nil
  else
    form_name = name.sub(/(::)?Form$/, "") # Song::Form => "Song"
    namespace = nil
  end

  active_model_name_for(form_name, namespace)
end