Module: AmountField::Helpers::FormHelper
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/amount_field/form_helper.rb
Overview
TODO/2010-04-23/tb remove redundant code using @template.amount_field(object, method, options) !?
Instance Method Summary collapse
Instance Method Details
#amount_field(object_name, method, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/amount_field/form_helper.rb', line 11 def amount_field(object_name, method, = {}) = I18n.t(:'number.amount_field.format', :raise => true) rescue {} = .merge(AmountField::ActiveRecord::Validations.configuration) .merge!(.delete(:format) || {}) object = .delete(:object) || instance_variable_get("@#{object_name}") # if no explicit value is given, we set a formatted one. In case of an error we take the # original value inserted by the user. if object.errors[method].blank? [:value] ||= number_with_precision(object.send(method), ) else [:value] ||= object.send("#{AmountField::Configuration.prefix}_#{method}") || object.send("#{method}_before_type_cast") end [:name] ||= "#{object_name}[#{AmountField::Configuration.prefix}_#{method}]" [:class] = "#{[:class]} #{AmountField::Configuration.css_class}" [:id] ||= "#{object_name}_#{method}" text_field(object_name, method, ) end |