module Padrino::Helpers::FormBuilder::DeprecatedBuilderMethods

Public Instance Methods

build_object(object_or_symbol) click to toggle source

Returns a new record of the type specified in the object

# 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) click to toggle source

Add a :invalid css class to the field if it contain an error.

# File lib/padrino-helpers/form_builder/deprecated_builder_methods.rb, line 16
def field_error(field, options)
  logger.warn "##{__method__} is deprecated"
  error = @object.errors[field] rescue nil
  error.blank? ? options[:class] : [options[:class], :invalid].flatten.compact.join(" ")
end
field_result() click to toggle source
# 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) click to toggle source
# File lib/padrino-helpers/form_builder/deprecated_builder_methods.rb, line 75
def merge_default_options!(field, options)
  logger.warn "##{__method__} is deprecated"
  options.reverse_merge!(:value => field_value(field), :id => field_id(field))
  options.merge!(:class => field_error(field, options))
end
nested_form?() click to toggle source
# 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) click to toggle source

Returns the class type for the given object.

# 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) click to toggle source

Returns the object’s models name.

# 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() click to toggle source
# File lib/padrino-helpers/form_builder/deprecated_builder_methods.rb, line 81
def result_options
  logger.warn "##{__method__} is deprecated"
  {
    :parent_form  => @options[:nested][:parent],
    :nested_index => @options[:nested][:index],
    :attributes_name => "#{@options[:nested][:association]}_attributes"
  }
end
root_form?() click to toggle source

Returns true if this form is the top-level (not nested). Returns a record from template instance or create a record of specified class.

# 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) click to toggle source

Returns true if the value matches the value in the field. field_has_value?(:gender, ‘male’)

# 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