Class: ActionView::Helpers::InstanceTag

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/helpers/date_and_time_helper.rb

Instance Method Summary collapse

Instance Method Details

#to_date_and_time_field_tag(options = {}, html_options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/action_view/helpers/date_and_time_helper.rb', line 13

def to_date_and_time_field_tag(options = {}, html_options = {})
  options = options.stringify_keys
  html_options = html_options.stringify_keys

  options["include_position"] = true unless options.has_key?("include_position")
  options["prefix"] ||= @object_name

  html_options["value"] = html_options.fetch("value"){ value_before_type_cast(object) }
  html_options["value"] &&= ERB::Util.html_escape(html_options["value"])
  { date: value_to_date(html_options["value"]),
    time: value_to_time(html_options["value"])
  }.inject("") do |output, (field_type, value)|
    html_options.merge!("id" => input_id_from_type(field_type, options),
                        "name" => input_name_from_type(field_type, options),
                        "type" => field_type,
                        "value" => value)
    output << tag("input", html_options)
  end
end