Module: AmountField::Helpers::FormTagHelper

Includes:
ActionView::Helpers::NumberHelper
Defined in:
lib/amount_field/form_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#amount_field_tag(name, value = nil, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/amount_field/form_tag_helper.rb', line 6

def amount_field_tag(name, value = nil, options = {})
  format_options = I18n.t(:'number.amount_field.format', :raise => true) rescue {}
  format_options = format_options.merge(AmountField::ActiveRecord::Validations.configuration)
  format_options.merge!(options.delete(:format) || {})
  
  # 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.
  options[:value] ||= number_with_precision(value.to_s, format_options)
  options[:name]  = "#{AmountField::Configuration.prefix}_#{name}"
  options[:class] = "#{options[:class]} #{AmountField::Configuration.css_class}"

  text_field_tag(name, value, options)
end