Rails select tag selected value

ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.1

Solution

You did everything right, just close the options `]` before the `:selected => :option`:

instead of `...], selected: :option ]))`, change to `...]], selected: :option ))`

So, your code should be:

<%= select_tag(:option, options_for_select([['All', 1], ['Co', 2], ['Bought', 3], ['View', 4], ['Top API', 5]], selected: :option )) %>

Problem

My tag: ``` <%= select_tag(:option, options_for_select([['All', 1], ['Co', 2], ['Bought', 3], ['View', 4], ['Top API', 5], :selected => :option ])) %> ``` How do I set the selected value to which option is selected. For example, if I select `['Bought', 3]`, and submit, `['All', 1]` option is selected. How can I display the selected value after the form is submitted.

Original source