0

how to make 'true' as default here ?

selected: true option is not working

<%= f.input :smoke, label: "Smoke", :collection => [[true, "You can"], [false, "You can't"]],
         label_method: :last, value_method: :first, as: :radio_buttons, selected: true %>
Said Kaldybaev
  • 9,380
  • 8
  • 36
  • 53

1 Answers1

5

Do you have any reasons to avoid setting default value in model or controller? Perhaps it's possible to set 'true' as default on view level with simple_form, but after that you will have to make two separate forms for new/edit actions or add extra logic to the view code (to correctly show 'default' true or actual value).

Otherwise, adding single line to your controller probably can solve the problem, and I don't see any side effects:

def new
  @model = Model.new
  @model.smoke = true # 'true' will be default
  ...
dimuch
  • 12,728
  • 2
  • 39
  • 23