Peter Marklund
2009-Sep-07 17:38 UTC
Form select should d string equality rather than object equality
Have you ever had a select box with ActiveRecord id:s as option values
and a param from the params hash as selection? Something like this:
<% form_tag do %>
<%= select_tag(:category_id,
options_for_select(Category.all.map { |c| [c.name, c.id] }, params
[:category_id])) %>
<%= submit_tag %>
<% end %>
I doesn''t work since values in the params hash are strings and model
ids are integers. I''ve patched the option_value_selected? method to do
comparisons on strings rather than objects:
https://rails.lighthouseapp.com/projects/8994/tickets/3142-make-select-options-in-forms-symbolstring-indifferent
Comments on this?
Thanks!
Peter Marklund
http://marklunds.com