Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9415 (closed defect: invalid)

Opened 3 years ago

Last modified 2 years ago

[PATCH] ActionView::Helpers::DateHelper.name_and_id_from_options

Reported by: anthonygreen Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

def name_and_id_from_options(options, type)
  options[:name] = (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
  options[:id] = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '')
end

changed to

def name_and_id_from_options(options, type)
  options[:name] ||= (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
  options[:id] ||= options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '')
end

allows form date helpers to pass html id and name attributes to select_html and not have them overwritten by name_and_id_from_options

Change History

09/10/07 04:41:13 changed by nzkoz

(In [7444]) Remove acts_as_list. Users are advised to install the new plugin. References #9415. [josh, nzkoz]

09/10/07 04:44:03 changed by nzkoz

Sorry for the erroneous commit message above.

12/17/07 16:38:30 changed by anthonygreen

  • type changed from enhancement to defect.

Seems this bug is more widespread becuase of the use of :field_name in the select form helpers rather than :name.

!#ruby

I suggest

def name_and_id_from_options(options, type)
  options[:name] ||= options[:field_name] || (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
  options[:id] ||= options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '')
end

and then trying to make the code generating the HTML name attribute consistant across helpers. 

12/19/07 13:55:00 changed by anthonygreen

  • status changed from new to closed.
  • resolution set to invalid.

use :prefix => 'string' to update the model part of the name attribute when using date helpers. Check other helpers calling name_and_id_from_options use the same hash