Pregunta

I have used a rails select tag to implement a multiple select feild in my application

<%= f.select(:tag, ['Phone', 'Email','Website','Address', 'Occupation'], {},  :id=>"multiple",:class=>"select2", :multiple=>"multiple" ,:style=>"width:200px" ) %>

The problem I am facing is that the value that the feild returs always contains some unwanted hyphens and quotes.For example if I select 'Phone' and 'Email' form the multiple select menu,the value that it returns is like this - --- - '' - Phone - Email

Why this happnens?I cant go forward further unless i can solve it,Any Clues?

I have added a Jscript to provide the look of a tiled tag feild in the view part

  <script>
    $('.select2').select2({ placeholder : '' });
 </script>

The problem is doesnot occur when i remove the above given script

¿Fue útil?

Solución

I guess, it should be written as below:

<%= f.select :tag, options_for_select(["Phone", "Email", "Website", "Address", "Occupation"]), :id=>"multiple",:class=>"select2", :multiple=>"multiple" ,:style=>"width:200px" %>

Edit: Try below option, it might be work for you:

<%= f.select(:tag,  %w[Phone Email Website Address Occupation], {},  :id=>"multiple",:class=>"select2", :multiple=>"multiple" ,:style=>"width:200px" ) %>

Also please refer http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M001624

Otros consejos

You could do str.gsub!(/\'/, '') and then str.gsub!(/-/, ''), although that's probably not a good idea.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top