Hey group,
In my view I’m iterating through the columns of a csv file to map my
DB fields to my csv columns. I’m using the map_fields plugin (http://
ramblingsonrails.com/map-fields-a-rails-plugin-to-ease-the-importing-
of-csv-files) to do this. I have already implemented this part of the
app. The field choices(mapping) are passed a hash parameter when the
form is submitted. I’m saving the hash in a serialized field. If that
field isn’t nil it uses my saved options (this is working). The
problem is my form doesn’t display those saved options as the default
choice in each of the select boxes when I bring it up a second time.
This is what I would like to implement, but can’t figure out how. It
seems pretty advanced, so any help would be appreciated.
The hash I save looks like this…
“fields”=>{“6”=>“1”, “1”=>“2”, “2”=>“3”, “3”=>“4”, “4”=>“5”, “5”=>“6”}
The ID is the column, and the value is the choice.
The choices are as follows…
In my view I have an @fields array that has the choices [1 =>
“Reading”, 2 => “Date”, 3 => ‘Month’] etc
portion of my view code…
<% (1…@rows[0].size).each do |c| -%>
<th><%= select_tag "fields[#{c}]", options_for_select
(@fields), :include_blank => true, :class => ‘field_options’ %>
<% end -%>
Somehow I want to dynamically get the default value for the select_tag
based upon the hash that got saved to the database. If a column
doesn’t have a default choice it would be blank.
If I was working with just one select field it would be easy, but I
don’t know how to say “if column = 1, then value = “Reading” if hash
is Saved”
I tried to keep my explanation as simple as possible. I’m willing to
compensate someone for their time if they are willing to help me. I
posted my the related files in the following pastie for a closer
look.
Thanks!
Chris