lunaclaire
2007-Nov-04 07:56 UTC
creating an array of key-value pairs for options_for_select
My situation is: * I''m using a select_tag form helper which shows a menu of names from a collection in a view * options_for_select works nicely here because I can just pass the collection in so, it looks like this <%= select_tag( :group_selection, options_for_select(@group_names)) %> problem: some of the strings in @group_names are too wide for the panel I want to display the menu in * so, I thought I''d truncate the names for display, but I still need the full names so that the selection passed back to the controller in params[:group_selection] will match the actual name of the group what''s cool is that options_for_select will take an array of key-value pairs, so I can put the truncated name in the first as the key and the original as the value and it works... when I hard code up an array as a test I want to write a helper function that would take @group_names and a truncation length and would return the array of key-value pairs described above... and that would be passed into options_for_select. This might be a simple ruby problem, but I havent found how to write the code to do. Any help will be much appreciated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---