Rails / Ruby单选按钮默认选中

时间:2014-02-10 21:57:32

标签: ruby-on-rails ruby radio-button haml

我有:

- [ 'here now', 'trip scheduled', 'planning a trip', 'already visited' ].each do |travel|
  %div.field.radio.small.snug.bind                  
    = f.radio_button :expected_travel, travel
    = label_tag "visitors_guide_request_expected_travel[#{travel}]", travel.titleize 

我需要默认选中为“现在这里”生成的单选按钮。最简单的方法是什么?

1 个答案:

答案 0 :(得分:1)

您可以将:checked选项传递到radio_button:

= f.radio_button :expected_travel, travel, :checked => travel == 'here now'

这将检查值为here now

的按钮