0

I'm trying to have selected or default value for a simple form collection like this:

= f.input :currency_symbol, collection: (Country.all.map{|c| "#        
  {c.currency_symbol}}), label: "Currency", input_html: {class: "    
  form-control chosen-select"}

and im trying to basically have a default value already selected. i tried specifying selected: '2', or default: '2' but nothing works. Both of these just select the first option in the collection list.

Any ideas? Thank you.

  • Have you seen/tried this one? http://stackoverflow.com/questions/9107751/rails-simple-form-how-to-set-selected-index-of-a-collection-when-page-loaded – Taryn East Feb 13 '17 at 02:35
  • @TarynEast. yes i have seen it. I dont see how it solves my question. There it is about updating the record that already exist and the value can be found easily. I have no problem with that. My problem is with the form when creating a new object. I want to be able to have as a default something that has never been selected before. –  Feb 13 '17 at 02:40
  • You pass the value to `selected` -> it shouldn't matter what you pass to it. Choose what you want the default to be... and pass that as per the other question. You will need to pass a value that is actually in the list... your list seems to be made of this: `Country.all.map{|c| "# {c.currency_symbol}" }` (note you're missing a closing quote which I have added)... which means that you probably need to pass a Country currency-symbol to `selected` – Taryn East Feb 13 '17 at 04:30

0 Answers0