Can anyone please tell me what's going on here, I've copied something
pretty much directly from rails guides, but it's just not doing what
it's supposed to!
1. the array of arrays is created from the @formations
2. prints this array of arrays [["4-3-3", "4-3-3"], ["5-3-2", "5-3-2"],
["4-4-2", "4-4-2"]]
(as I expect)
3. creates the select box, and hard coded asks for index 2 to be
currently selected, as on rails docs here : <%=
options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %>
However when I look at the page, the wrong selection is selected, always
index 0, not index 2.
Can anyone please tell me what's going on here! Or is this a bug?
Thanks for that, it works exactly as you said! cheers, now I have the
line
<%= f.select(:formation_csv, @formations) %>
and it magically knows which one to select.
I'm still v curios as to why the "options_for_select(formations_array,
2)" didn't do anything, is it because when I'm using this in conjunction
with the form_helper, ie f.select as opposed to select_tag, the
options_for_select method becomes redundant, or different?
Thanks for that, it works exactly as you said! cheers, now I have the
line
<%= f.select(:formation_csv, @formations) %>
and it magically knows which one to select.
I’m still v curios as to why the "options_for_select(formations_array,
2)" didn’t do anything, is it because when I’m using this in conjunction
with the form_helper, ie f.select as opposed to select_tag, the
options_for_select method becomes redundant, or different?
Yeah, it’s redundant. Your code was also wrong The second paramater needs to be the value of the selected object, not the array index. So options_for_select(formations_array, “5-3-2”) would probably have worked. It’s a bad idea though in a resource-based form though.
Glad you’ve got it sorted! My experience with Rails says if something feels like it’s getting unnecessarily complex, you’re probably doing it wrong!