# Advanced Question select\_tag (default options) - created from an array. Willing to compensate someo

**URL:** <https://www.ruby-forum.com/t/advanced-question-select-tag-default-options-created-from-an-array-willing-to-compensate-someo/177936>\
**Category:** Rails\
**Created:** [October 26, 2009, 10:37pm UTC](https://www.ruby-forum.com/t/advanced-question-select-tag-default-options-created-from-an-array-willing-to-compensate-someo/177936 "2009-10-26T22:37:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [October 26, 2009, 10:37pm UTC](https://www.ruby-forum.com/t/advanced-question-select-tag-default-options-created-from-an-array-willing-to-compensate-someo/177936/1 "2009-10-26T22:37:45Z")

</div>

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-](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.

[http://pastie.org/670747](http://pastie.org/670747)

Thanks!

Chris

---

<div class="post-metadata">

**Author:** ![internetchris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c68b51/32.png) [@internetchris](https://www.ruby-forum.com/u/internetchris)\
**Post date:** [October 27, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/advanced-question-select-tag-default-options-created-from-an-array-willing-to-compensate-someo/177936/2 "2009-10-27T23:19:29Z")

</div>

I found a solution. I posted it on the railsforum if anyone is  
interested.

[http://railsforum.com/viewtopic.php?id=35139](http://railsforum.com/viewtopic.php?id=35139)

Thanks,

Chris

On Oct 26, 3:36 pm, internetchris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
