class EasyForm::Field

Attributes

args[RW]
builder[RW]
options[RW]
type[RW]

Public Class Methods

class_merge(h1, h2) click to toggle source
# File lib/easy_form/field.rb, line 39
def self.class_merge(h1, h2)
  if h2[:class]
    h2[:class] << ' ' <<  h1[:class].to_s
  end
  h1.merge(h2)
end
new(builder, args, &block) click to toggle source
# File lib/easy_form/field.rb, line 4
def initialize(builder, args, &block)
  @builder = builder
  @options = args.extract_options!
  @args    = args
  @block   = block
end

Public Instance Methods

field() click to toggle source
# File lib/easy_form/field.rb, line 11
def field
  @args[1]
end
input(options={}) click to toggle source
# File lib/easy_form/field.rb, line 19
def input(options={})
  builder.send(*args, self.class.class_merge(@options, options), &@block)
end
label_text() click to toggle source
# File lib/easy_form/field.rb, line 27
def label_text
  options[:label] || model.human_attribute_name(field)
end
model() click to toggle source
# File lib/easy_form/field.rb, line 15
def model
  builder.object.class
end
required?() click to toggle source
# File lib/easy_form/field.rb, line 23
def required?
  field && model.validators_on(field).any?{ActiveRecord::Validations::PresenceValidator}
end
template_name() click to toggle source
# File lib/easy_form/field.rb, line 35
def template_name
  builder.options[:template] || options[:template] || :default
end
to_s() click to toggle source
# File lib/easy_form/field.rb, line 31
def to_s
  EasyForm::Template.render(template_name, binding)
end