Module: MonkeyForms::Form::InstanceMethods
- Defined in:
- lib/monkey_forms.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#html_error_messages ⇒ Object
TODO not sure what’s best here.
- #initialize(options = {}) ⇒ Object
- #persisted? ⇒ Boolean
- #save_to_storage! ⇒ Object
- #to_key ⇒ Object
- #to_model ⇒ Object
- #to_param ⇒ Object
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
28 29 30 |
# File 'lib/monkey_forms.rb', line 28 def attributes @attributes end |
Instance Method Details
#html_error_messages ⇒ Object
TODO not sure what’s best here
35 36 37 |
# File 'lib/monkey_forms.rb', line 35 def errors..join("<br />") end |
#initialize(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/monkey_forms.rb', line 51 def initialize = {} _run_initialize_callbacks do form_params = .delete(:form) || {} @options = @options.each do |key, value| instance_variable_set "@#{key}", value end # Load the saved form from storage @attributes = if self.class.form_storage self.class.form_storage.load(@options) else ActiveSupport::HashWithIndifferentAccess.new end # Merge in this form's params DeepMerge.deep_merge!(form_params, @attributes) self.class.attributes.each do |a| @attributes[a] ||= "" if self.class.strip_attributes? if @attributes[a].class == String @attributes[a].strip! elsif @attributes[a].class == Array @attributes[a].each do |v| v.strip! if v.class == String end end end end end end |
#persisted? ⇒ Boolean
30 31 32 |
# File 'lib/monkey_forms.rb', line 30 def persisted? false end |
#save_to_storage! ⇒ Object
86 87 88 89 |
# File 'lib/monkey_forms.rb', line 86 def save_to_storage! @options[:attributes] = @attributes self.class.form_storage.save(@options) end |
#to_key ⇒ Object
47 48 49 |
# File 'lib/monkey_forms.rb', line 47 def to_key nil end |
#to_model ⇒ Object
39 40 41 |
# File 'lib/monkey_forms.rb', line 39 def to_model self end |
#to_param ⇒ Object
43 44 45 |
# File 'lib/monkey_forms.rb', line 43 def to_param nil end |