I was working on this a couple of months back and could not figure out what I was doing wrong. I came back to it today and wanted to post again to see if any of you had an idea. Here is the problem. I have this code: <select name="myrep[RepFor][]" size="3" multiple="multiple"> <%= options_from_collection_for_select(@rflists, "id", "keyword", @selected) %> </select> The field I am storing is called RepFor in the myrep table. The options for the dropdown comes from a keyword table that have an id and name. The options I want have been fed into rflists. This all works good and displays properly with a multiple select dropdown with the proper names and values. Here is the html it renders: <select name="myrep[RepFor][]" size="3" multiple="multiple"> <option value="1808">Car Insurance</option> <option value="1809">Home Insurance</option> <option value="1810">Technology</option> <option value="1811">Accounting</option> <option value="1812">Legal</option> So if I select Car Insurance, Home Insurance and Technology and submit it this is what gets written to the DB. Exactly as shown below. --- - "1808" - "1809" - "1810" When I reopen the form nothing is selected. Now if I manually set @selected in my code as follows it selects the items I have forced when I reopen the form: <% @selected = 1808, 1809, 1810 %> <select name="myrep[RepFor][]" size="3" multiple="multiple"> <%= options_from_collection_for_select(@rflists, "id", "keyword", @selected) %> </select> My question is what do I need to do to make the select write the data to the DB the same way I set it in @selected. Is there something that has to be done in the controller to keep it from being written as follows: --- - "1808" - "1809" - "1810" or do I need to do something special when reading it back? Thanks for your help. Jim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> --- - "1808" - "1809" - "1810"what is that ^ a string? an array? a hash? are they going to the db individually or seperatly hows this after the save in the post code put a missing method in and post the controller code as well as the params dump so we have a better idea what your talking about -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That is a Var Char in a mysql DB. All the selections sit in one field, the RepFor field in the table. The code: <select name="myrep[RepFor][]" size="3" multiple="multiple"> <%= options_from_collection_for_select(@rflists, "id", "keyword", @selected) %> </select> writes that to the RepFor field in the myrep table. There is no special code in controller. I guess thats my question. What needs to be in there to write the values seperated by commas so that when I pull the field back in edit mode the entries are selected on the form. Alternately what do I need to do to get the multi select as I have it to work. Its crazy to me that this is not so straightforward. I must be missing some easy step. Do I need to do some sort of translation on the controller side? Do I need to store it in the DB in some other way? On May 16, 11:29 pm, Keynan Pratt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > --- - "1808" - "1809" - "1810" > > what is that ^ > > a string? > an array? > a hash? > > are they going to the db individually or seperatly > > hows this after the save in the post code put a missing method in and > post > the controller code as well as the params dump so we have a better idea > what your talking about > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---