Module: Reform::Form::ActiveModel::ClassMethods
- Defined in:
- lib/reform/form/active_model.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
this module is only meant to extend (not include).
Instance Method Summary collapse
-
#model(main_model, options = {}) ⇒ Object
Set a model name for this form if the infered is wrong.
- #model_name ⇒ Object
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, ={}) self. = [main_model, ] end |
#model_name ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reform/form/active_model.rb', line 44 def model_name if form_name = .first.to_s.camelize namespace = .last[:namespace].present? ? .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 |