This project is archived and is in readonly mode.

#5056 ✓resolved
rk

select tags do not check the :selected option properly

Reported by rk | July 6th, 2010 @ 11:53 PM | in 3.x

Hi,

When using the helpers which generate select tags and their options, I've run into a relatively universal problem.

<%= f.select :plan_id, ... %>
# and
<%= f.select :plan_id, ..., :selected => params[:subscription].try(:[], :plan_id) %>

Will both generate a nice big list of plans, but wont select one after being submitted (if errors appear or the form generates a preview first).

The simple fix is the following:

<%= f.select :plan_id, ..., :selected => params[:subscription].try(:[], :plan_id).to_i %>

Yup, that simple. The type that gets read from the record is Fixnum while the type read from the post is String, and of course no string equals a fixnum (by default). A little type coercion could go a ways to fixing this.

Comments and changes to this ticket

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>

Attachments

Referenced by

Pages