Reputation: 13
I am getting a string seperated with pipe. I want to show it in dropdown box. How can i achieve that?Asume the data i am getting is in this format
0123~Apple|Banana|Grapes|Oranges
Upvotes: 0
Views: 93
Reputation: 7366
Use this code to get array of string:
str = "0123~Apple|Banana|Grapes|Oranges"
@options = str.split('~')[1].split("|") #=> ["Apple", "Banana", "Grapes", "Oranges"]
And to generate select tag use this:
<%= select_tag "xyz", options_for_select(@options) %>
Upvotes: 1