Collection_select help

I can’t figure out how to get the collection_select to correctly
identify and select the appropriate option in the drop down to begin
with. i have checked that charge.offense_level contains the correct
value to begin with (a number between 1 and 10) but the view still
defaults to the first option and not the one contained in the
charge.offense_level. what am i doing wrong? any suggestions? I have
also tried: <%= collection_select “charge”, “offense_level”,
@charge_types, :id, :full_name %> but that doesn’t work either.

@charges contains multiple records obtained from a find_by_sql query.
each record has 3 fields: charge_name, charge_id_number, offense_level should be equal to the @charge.offense_level

the view - update_charges.rhtml:

Add missing records to charges table

<%= start_form_tag %>

<%= render :partial => 'charge', :collection => @charges %>
Charge id number Charge name Classification level
<%= submit_tag 'Save' %> <%= end_form_tag %>

the partial - _charge.rhtml:

<%= hidden_field_tag "charge[#{charge_counter}][charge_id_number]", charge.charge_id_number %><%= charge.charge_id_number %> <%= text_field_tag "charge[#{charge_counter}][name]", charge.charge_name, :size => 50 %> ][offense_level]" name="charge[<%= charge_counter %>][offense_level]"> <%= options_from_collection_for_select @charge_types, 'id', 'full_name' %>

here is the generated html from the source:

52130005 Capital Felony First Degree Felony Second Degree Felony Third Degree Felony State Jail Felony Class A Misdemeanor Class B Misdemeanor Class C Misdemeanor Unknown Felony Unknown Misdemeanor

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs