Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

formtastic select, one entry selected as default

I have an input which I render :as => :select. I would like one option to be selected as default. How would I go about that?

Thanks, Hendrik

like image 683
Hendrik Avatar asked Apr 25 '12 16:04

Hendrik


2 Answers

If you are not making a form off of a model.

= semantic_form_for :report do |f|
  = f.inputs name: 'Choose a Report Year' do
    = f.input :report_year, collection: options_for_select(['2010', '2011', '2012', '2013'], '2012')
    = f.action :submit, label: 'Submit Year', as: :button
like image 108
idrinkpabst Avatar answered Oct 29 '22 16:10

idrinkpabst


So set a preselected answer you have to associate your object with the desired value.

countries = ['USA','Germany']
@user.country = countries.first

That works for me.

like image 26
Hendrik Avatar answered Oct 29 '22 15:10

Hendrik