Here's what I would like to do (in rails 2.2.2):
<% if params[:cruise_info] %>
<%= collection_select :cabin_type, :cabin_type_id,
CabinType.find_by_status(1).collect {|ct| ct}, :id, :name, {:selected =>
params[:cruise_info][:cabin_type_id]}%>
<% end %>
The intent here is, on re-rendering the page (after a validation
failure), I don't want the end-user to be required to make the selection
again. I have half a dozen collection_selects in this form that are
being returned from partials and are embeded with :fields_for, so
they're not automatically retaining their selections.
Most of my search results are Bug reports for this, but they're more
than 2 years old. It's gotta be fixed by now right? I have to be doing
something wrong? I just can't see it. I've tried using select,
options_from_collection_for_select, and have the same issue with all of
them. I've tried different variations, like putting it in the options
=> {} and in html_options => {}...and nothing. I've tried :selected,
:selected_value, I even tried using :include_blank => {...}, which i
knew wouldn't work, but thought it worth a try. I've tried to_s on the
params (which btw are an integer), but i'm not even seeing the
"selected" option showing up in the html source.
Sorry for being so long winded, I want to insure I include enough
information to get this solved.
Any advice?
Thanks in advance
--
Posted via http://www.ruby-forum.com/.
Thanks for the info Fred, but do you know of any convention for handling
this kind of problem now?
Thanks again Fred, I think I'll have to just write out the selects. I
was hoping that maybe this was more common and there would be a "rails"
solution for it. The engineering of my forms must be out of whack with
convention. I'll swing over to railscasts for a re-review of complex
forms.