Module: Padrino::Helpers::FormBuilder::DeprecatedBuilderMethods
- Included in:
- AbstractFormBuilder
- Defined in:
- lib/padrino-helpers/form_builder/deprecated_builder_methods.rb
Instance Method Summary collapse
-
#build_object(symbol) ⇒ Object
Returns a new record of the type specified in the object.
-
#field_error(field, options) ⇒ Object
Add a :invalid css class to the field if it contain an error.
- #field_result ⇒ Object
- #merge_default_options!(field, options) ⇒ Object
- #nested_form? ⇒ Boolean
-
#object_class(explicit_object) ⇒ Object
Returns the class type for the given object.
-
#object_model_name(explicit_object = object) ⇒ Object
Returns the object’s models name.
- #result_options ⇒ Object
-
#root_form? ⇒ Boolean
Returns true if this form is the top-level (not nested).
-
#values_matches_field?(field, value) ⇒ Boolean
Returns true if the value matches the value in the field.
Instance Method Details
#build_object(symbol) ⇒ Object
Returns a new record of the type specified in the object
31 32 33 34 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 31 def build_object(object_or_symbol) logger.warn "##{__method__} is deprecated" object_or_symbol.is_a?(Symbol) ? @template.instance_variable_get("@#{object_or_symbol}") || object_class(object_or_symbol).new : object_or end |
#field_error(field, options) ⇒ Object
Add a :invalid css class to the field if it contain an error.
16 17 18 19 20 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 16 def field_error(field, ) logger.warn "##{__method__} is deprecated" error = @object.errors[field] rescue nil error.blank? ? [:class] : [[:class], :invalid].flatten.compact.join(" ") end |
#field_result ⇒ Object
68 69 70 71 72 73 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 68 def field_result logger.warn "##{__method__} is deprecated" result = [] result << object_model_name if root_form? result end |
#merge_default_options!(field, options) ⇒ Object
75 76 77 78 79 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 75 def (field, ) logger.warn "##{__method__} is deprecated" .reverse_merge!(:value => field_value(field), :id => field_id(field)) .merge!(:class => field_error(field, )) end |
#nested_form? ⇒ Boolean
22 23 24 25 26 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 22 def nested_form? logger.warn "##{__method__} is deprecated" @options[:nested] && @options[:nested][:parent] && @options[:nested][:parent].respond_to?(:object) is_nested && object.respond_to?(:new_record?) && !object.new_record? && object.id end |
#object_class(explicit_object) ⇒ Object
Returns the class type for the given object.
48 49 50 51 52 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 48 def object_class(explicit_object) logger.warn "##{__method__} is deprecated" explicit_object.is_a?(Symbol) ? explicit_object.to_s.camelize.constantize : explicit_object.class @object.respond_to?(field) ? @object.send(field) : '' end |
#object_model_name(explicit_object = object) ⇒ Object
Returns the object’s models name.
39 40 41 42 43 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 39 def object_model_name(explicit_object=object) logger.warn "##{__method__} is deprecated" return @options[:as] if root_form? && @options[:as].is_a?(Symbol) explicit_object.is_a?(Symbol) ? explicit_object : explicit_object.class.to_s.underscore.gsub(/\//, '_') end |
#result_options ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 81 def logger.warn "##{__method__} is deprecated" { :parent_form => @options[:nested][:parent], :nested_index => @options[:nested][:index], :attributes_name => "#{@options[:nested][:association]}_attributes" } end |
#root_form? ⇒ Boolean
Returns true if this form is the top-level (not nested). Returns a record from template instance or create a record of specified class.
58 59 60 61 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 58 def root_form? logger.warn "##{__method__} is deprecated" !nested_form? end |
#values_matches_field?(field, value) ⇒ Boolean
Returns true if the value matches the value in the field. field_has_value?(:gender, ‘male’)
8 9 10 11 |
# File 'lib/padrino-helpers/form_builder/deprecated_builder_methods.rb', line 8 def values_matches_field?(field, value) logger.warn "##{__method__} is deprecated" value.present? && (field_value(field).to_s == value.to_s || field_value(field).to_s == 'true') end |