class ActionView::Helpers::InstanceTag
Public Instance Methods
to_date_and_time_field_tag(options = {}, html_options = {})
click to toggle source
# 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
Private Instance Methods
input_id_from_type(type, options = {})
click to toggle source
Returns the id attribute for the input tag.
=> "post_written_on_1"
# File lib/action_view/helpers/date_and_time_helper.rb, line 59 def input_id_from_type(type, options = {}) id = input_name_from_type(type, options).gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '') id = options["namespace"] + '_' + id if options["namespace"] id end
input_name_from_type(type, options = {})
click to toggle source
Returns the name attribute for the input tag.
=> post[written_on(1)]
# File lib/action_view/helpers/date_and_time_helper.rb, line 45 def input_name_from_type(type, options = {}) prefix = options["prefix"] || ActionView::Helpers::DateAndTimeHelper::DEFAULT_PREFIX prefix += "[#{options['index']}]" if options.has_key?("index") field_name = method_name.dup if options["include_position"] field_name += "(#{ActionView::Helpers::DateAndTimeHelper::POSITION[type]})" end options["discard_type"] ? prefix : "#{prefix}[#{field_name}]" end
value_to_date(value)
click to toggle source
# File lib/action_view/helpers/date_and_time_helper.rb, line 35 def value_to_date(value) value && value.to_date.to_s end
value_to_time(value)
click to toggle source
# File lib/action_view/helpers/date_and_time_helper.rb, line 39 def value_to_time(value) value && value.strftime("%H:%M") end