Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default selected value for Rails SimpleForm select box

I'm trying to figure out how to set the selected option of a select box generated by SimpleForm. My code is along the lines of:

<%= simple_form_for(@user) do |f| %>
  <%= f.association :store, default: 1 %>

Of course the default: 1 part does not work.

TIA

like image 274
Eric Muyser Avatar asked May 04 '12 00:05

Eric Muyser


2 Answers

Use the following:

selected: 1
like image 156
0x4a50 Avatar answered Nov 14 '22 03:11

0x4a50


You can now use the following:

<%= f.association :store, selected: 1 %>
like image 8
Abram Avatar answered Nov 14 '22 02:11

Abram