This project is archived and is in readonly mode.
select helper breaks for numerical values and displays
Reported by Sam Woodard | September 14th, 2009 @ 11:52 PM
If I have builder.select(:method, [1,2,3]) etc, I get
123
This is what I would expect. However if my_instance.method returns 2, the options with value, "2", does not get selected.
However if I do,
builder.select(:method, [1,2,3].collect{|e| [e, "a#{e}"]})
thus appending an 'a' before the value of each element, the behavior works as expected.
I think that the method should match on "2" == "2" and put out selected="selected" and not require an alpha character prefix.
Thanks in advance.
Sam
Comments and changes to this ticket
-
CancelProfileIsBroken September 25th, 2009 @ 12:11 PM
- Tag set to bugmash
-
Alex Kahn September 26th, 2009 @ 03:06 AM
I can reproduce this. What Sam is saying is that when using the select method in a form_for block and viewing an edit action on a resource, the "selected" option is set if the value for the field is a String but not if it's a Fixnum.
So, if Post.category == 'bar', and the view code is
f.select :category, ['foo', 'bar', 'baz']
, bar will be selected when you edit the post.But if Post.category == 3, and the view code is
f.select :category, [1,2,3]
, none of the options in the select will be marked 'selected'. -
Elad Meidar September 26th, 2009 @ 06:56 AM
-1 unable to reproduce, maybe a failing test would make some sense into it.
-
Elad Meidar September 26th, 2009 @ 07:04 AM
@Sam: also, if you use options_for_select([1,2,3], :selected => 2) it's working just fine. besides, it seems like you are trying to create a element that is not related to an ActiveRecord instance attribute, if that's the case... why not code it as plain HTML ?
-
Elomar França September 26th, 2009 @ 04:35 PM
Unable to reproduce, neither in 2-3-stable nor in master.
-
sr.iniv.t September 26th, 2009 @ 07:08 PM
-1 not reproducible on 2-3-stable.
I have attached a patch to verify that select tag chooses the right option even if the field is numeric. I'm a newbie, so can someone please verify the patch and let me know if the test is right? Thanks!
-
John Trupiano September 26th, 2009 @ 09:44 PM
@sr.iniv.t this patch does not apply cleanly for me. I have attached a new patch.
-
Ben Marini September 27th, 2009 @ 12:21 AM
However if my_instance.method returns 2, the options with value, "2", does not get selected. @sam to clarify, does my_instance.method return a String or a Fixnum? I'm guessing it returns a string, and that's why it doesn't work. You could probably fix it with f.select :category, %w(1 2 3)
-
Ben Marini September 27th, 2009 @ 12:23 AM
Whoops let me try that again...
<< However if my_instance.method returns 2, the options with value, "2", does not get selected.
@sam to clarify, does my_instance.method return a String or a Fixnum? I'm guessing it returns a string, and that's why it doesn't work. You could probably fix it with
f.select :category, %w(1 2 3)
-
Sam Woodard January 10th, 2010 @ 05:23 PM
- Tag cleared.
This is a bug that I have been able to reproduce over and over again, for those of you that say it is not. Can we resume this conversation? This bug is quite annoying. I apologize that I reported the bug and then did not follow up.
-
Rohit Arondekar June 17th, 2010 @ 08:25 AM
Can somebody confirm if this issue is resolved in rails 2.3.8 and whether this ticket can be closed?
-
José Valim June 22nd, 2010 @ 04:34 PM
- State changed from new to invalid
Please add a comment if this issue still exists.
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>