views:

10

answers:

1

I have got about 9 combo box in registration form and i would like to save all of them as blob data type in mysql and retrieve them in edit form my view form looks like the following

<%= select("pcs","pc_info[HDD]",options_for_select(["---Select---","20GB","40GB","160GB","250GB","Other"]"), {:style => "width:142px"}) %>    </td>
 <%= select("pcs","pc_info[DRIVE]",options_for_select(["---Select---","Combo Drive","DVD Writer","Other"]), {:style => "width:142px"}) %>

pc_info is the blob data type in MySQL It could save successfully to MySQL My Question is how to retrieve blob data type value and make the combo box selected according to those values.

A: 

blob data is just text, so you will have to retrieve it and then parse it into an array for the options in the select.

ruby-1.8.7-p249 > '"20GB","40GB","160GB","250GB","Other"'.split(",")
 => ["\"20GB\"", "\"40GB\"", "\"160GB\"", "\"250GB\"", "\"Other\""] 

so you should be able to use that split methods to build an array.

@pc.pc_info.split(",")

and potentially use gsub to pull out the escaped quotes, or store the blob without internal quotes in the db

ruby-1.8.7-p249 > "20GB, 40GB, 60GB".split(",")
 => ["20GB", " 40GB", " 60GB"] 

and now that array is ready for your collection parameter in your select_tag

Jed Schneider