Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

DateTimeSelector does not create proper name attribute for new records

#6053

Rails 3.0.1

I am using time_select in a dynamically create field with field_for and the prefix it creates for a new object is missing the empty index array. The attribute it creates is: name="day[new_rule_attributes][start(1i)]" but it should be name="day[new_rule_attributes][][start(1i)]". This would be consistent with other fields generated the same way. For example, on the same form f.text_field creates name="day[new_rule_attributes][][action]".

The cause appears to be in the private function input_name_from_type in date_helper.rb:

def input_name_from_type(type)
  prefix = @options[:prefix] || ActionView::Helpers::DateTimeSelector::DEFAULT_PREFIX
  prefix += "[#{@options[:index]}]" if @options.has_key?(:index)

  field_name = @options[:field_name] || type
  if @options[:include_position]
    field_name += "(#{ActionView::Helpers::DateTimeSelector::POSITION[type]}i)"
  end

  @options[:discard_type] ? prefix : "#{prefix}[#{field_name}]"
end

In line 866 (3rd line above) the array is only added if the object has a key (set somewhere earlier). Shouldn't the proper behaviour be to add an empty array if there was no key?

Reported by Robert Sharp · November 24th, 2010 @ 10:27 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Robert Sharp
    Robert Sharp

    Suggest this is ditched. Seems to cause date_select to put in brackets where rails does not expect them. Reverted to original code and used :index=>'' to get the empty brackets where they are needed.

    Is it just me or is this not really working as it should? Why should I have to be concerned with forcing these brackets in for some fields and not for others? Either the design should surface the issue or hide it, not a mixture of both?

    December 7th, 2010 @ 04:31 PM

  2. rails
    rails
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    March 8th, 2011 @ 12:00 AM

  3. rails
    rails
    • State changed from open to stale

    March 8th, 2011 @ 12:00 AM