selected value for options_from_collection_for_select

Hey,

I am trying to get a select list with a selected value in it. Even if I put in an integer, like this,

<%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", 3)) %>

the list still displays the first option (No Contract) in the list.

What am I doing wrong? I've looked all over and it looks like this should be working.

Joe Peck wrote:

Hey,

I am trying to get a select list with a selected value in it. Even if I put in an integer, like this,

<%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", 3)) %>

the list still displays the first option (No Contract) in the list.

What am I doing wrong? I've looked all over and it looks like this should be working.

I've tried using "to_i", but it still generates the wrong "selected" value. <%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", fruit.kind_id.to_i)) %>

generates

<select id="70" name="70"><option>No Contract</option><option value="3" selected="selected">40 bucks for a PR 10 Links</option> <option value="7">Antidisestablishmentarialism</option></select>

Joe Peck wrote:

Hey,

I am trying to get a select list with a selected value in it. Even
if I put in an integer, like this,

<%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", 3)) %>

the list still displays the first option (No Contract) in the list.

What am I doing wrong? I've looked all over and it looks like this should be working.

I've tried using "to_i", but it still generates the wrong "selected" value. <%= select_tag(fruit.id, "<option>No Contract</option>" + options_from_collection_for_select(@fruit_types, "id", "kind", fruit.kind_id.to_i)) %>

generates

<select id="70" name="70"><option>No Contract</option><option
value="3" selected="selected">40 bucks for a PR 10 Links</option> <option value="7">Antidisestablishmentarialism</option></select>

What's the value of fruit.kind_id ?

Fred