This project is archived and is in readonly mode.
select helper breaks for numerical values and displays
-
CancelProfileIsBroken
- Tag set to bugmash
-
Alex Kahn
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
-1 unable to reproduce, maybe a failing test would make some sense into it.
-
Elad Meidar
@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
Unable to reproduce, neither in 2-3-stable nor in master.
-
sr.iniv.t
-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!
-
Elad Meidar
@sr.iniv.t - is this patch for 2-3-stable ?
-
sr.iniv.t
@Elad - yes.
-
John Trupiano
@sr.iniv.t this patch does not apply cleanly for me. I have attached a new patch.
-
Ben Marini
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
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
- 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.
-
Sam Woodard
seems to be fixed in 2.3.5
-
Rohit Arondekar
Can somebody confirm if this issue is resolved in rails 2.3.8 and whether this ticket can be closed?
