formtastic select, one entry selected as default

Hendrik picture Hendrik · Apr 25, 2012 · Viewed 9.3k times · Source

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

Answer

idrinkpabst picture idrinkpabst · May 29, 2013

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