user2603796
user2603796

Reputation:

How to add selected attribute in f.select helper in rails?

i have written the f.select helper for this code

    <select> 
              <option>abc</option>
              <option>def</option>
              <option selected>ghi</option>
    </select>

    <%= f.select(:xFields, ['abc', 'def', 'ghi]) %>

How do i make option 'ghi' selected as default?

Upvotes: 0

Views: 412

Answers (2)

dax
dax

Reputation: 10997

edit

try this:

<%= f.select options_for_select(:xFields, ['abc', 'def', 'ghi'], 'ghi') %>

the following should work

<%= f.select(:xFields, [['ghi'], 'abc', 'def']) %>

based on Rails 3: f.select - options_for_select

Upvotes: 1

user2603796
user2603796

Reputation:

This is working

         <%= f.select(:xFields, options_for_select( ['abc', 'def', 'ghi'], 'ghi')) %>

Upvotes: 0

Related Questions