Class: EasyForm::Field
- Inherits:
-
Object
- Object
- EasyForm::Field
- Defined in:
- lib/easy_form/field.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#builder ⇒ Object
Returns the value of attribute builder.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #field ⇒ Object
-
#initialize(builder, args, &block) ⇒ Field
constructor
A new instance of Field.
- #input(options = {}) ⇒ Object
- #label_text ⇒ Object
- #model ⇒ Object
- #required? ⇒ Boolean
- #template_name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(builder, args, &block) ⇒ Field
Returns a new instance of Field.
4 5 6 7 8 9 |
# File 'lib/easy_form/field.rb', line 4 def initialize(builder, args, &block) @builder = builder @options = args. @args = args @block = block end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
3 4 5 |
# File 'lib/easy_form/field.rb', line 3 def args @args end |
#builder ⇒ Object
Returns the value of attribute builder.
3 4 5 |
# File 'lib/easy_form/field.rb', line 3 def builder @builder end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/easy_form/field.rb', line 3 def @options end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/easy_form/field.rb', line 3 def type @type end |
Instance Method Details
#field ⇒ Object
11 12 13 |
# File 'lib/easy_form/field.rb', line 11 def field @args[1] end |
#input(options = {}) ⇒ Object
19 20 21 |
# File 'lib/easy_form/field.rb', line 19 def input(={}) builder.send(*args, @options.merge(), &@block) end |
#label_text ⇒ Object
27 28 29 |
# File 'lib/easy_form/field.rb', line 27 def label_text [:label] || model.human_attribute_name(field) end |
#model ⇒ Object
15 16 17 |
# File 'lib/easy_form/field.rb', line 15 def model builder.object.class end |
#required? ⇒ Boolean
23 24 25 |
# File 'lib/easy_form/field.rb', line 23 def required? field && model.validators_on(field).any?{ActiveRecord::Validations::PresenceValidator} end |
#template_name ⇒ Object
35 36 37 |
# File 'lib/easy_form/field.rb', line 35 def template_name builder.[:template] || [:template] || :default end |