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?



64
65
66
67
68
69
# File 'lib/reform/form/active_model.rb', line 64

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


76
77
78
# File 'lib/reform/form/active_model.rb', line 76

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

#model_nameObject



80
81
82
83
84
85
86
87
88
# File 'lib/reform/form/active_model.rb', line 80

def model_name
  if model_options
    form_name = model_options.first.to_s.camelize
  else
    form_name = name.sub(/(::)?Form$/, "") # Song::Form => "Song"
  end

  active_model_name_for(form_name)
end