This project is archived and is in readonly mode.

#6053 ✓stale
Robert Sharp

DateTimeSelector does not create proper name attribute for new records

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

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?

Comments and changes to this ticket

  • Robert Sharp

    Robert Sharp December 7th, 2010 @ 04:31 PM

    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?

  • rails

    rails March 8th, 2011 @ 12:00 AM

    • 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.

  • rails

    rails March 8th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages