Class: Tramway::Core::ApplicationForm
- Inherits:
-
Reform::Form
- Object
- Reform::Form
- Tramway::Core::ApplicationForm
- Defined in:
- app/forms/tramway/core/application_form.rb
Class Method Summary collapse
Instance Method Summary collapse
- #form_properties(**args) ⇒ Object
-
#initialize(object) ⇒ ApplicationForm
constructor
A new instance of ApplicationForm.
- #properties ⇒ Object
- #submit(params) ⇒ Object
Constructor Details
#initialize(object) ⇒ ApplicationForm
Returns a new instance of ApplicationForm.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/forms/tramway/core/application_form.rb', line 3 def initialize(object) super(object).tap do @@associations&.each do |association| = object.class.reflect_on_all_associations(:belongs_to).select do |a| a.name == association.to_sym end.first&. next unless class_name = [:class_name].constantize self.class.send(:define_method, "#{association}=") do |value| super class_name.find value end end end end |
Class Method Details
.association(property) ⇒ Object
33 34 35 36 37 |
# File 'app/forms/tramway/core/application_form.rb', line 33 def association(property) properties property @@associations ||= [] @@associations << property end |
Instance Method Details
#form_properties(**args) ⇒ Object
24 25 26 |
# File 'app/forms/tramway/core/application_form.rb', line 24 def form_properties(**args) @form_properties = args end |
#properties ⇒ Object
28 29 30 |
# File 'app/forms/tramway/core/application_form.rb', line 28 def properties @form_properties end |
#submit(params) ⇒ Object
19 20 21 22 |
# File 'app/forms/tramway/core/application_form.rb', line 19 def submit(params) raise 'ApplicationForm::Params should not be nil'.inspect unless params save if validate params end |