我正在 Rails3 和 Formtastic 中构建一个表单。我有以下领域:
<%= f.input :housing, :as => :radio, :collection => {"Awesome" => "one", "Great" => "two", "Nice" => "three"} %>
生成类似于以下内容的 HTML:
<input id="post_one" name="post" type="radio" value="one" />Awesome</label>
<input id="post_two" name="post" type="radio" value="two" />Great</label>
<input id="post_three" name="post" type="radio" value="three" /> Nice</label>
那工作完美无缺!
现在我想知道如何传入一个将“Great”标记为默认(选定)值的选项。我尝试执行以下操作,但无法正常工作。
<%= f.input :housing, :as => :radio, :collection => {"Awesome" => "one", "Great" => "two", "Nice" => "three"}, :default => "one" %>
我也尝试过传入,:selected
而:checked
不是:default
但是唉,它不起作用。
有人知道这样做的方法吗?
谢谢!
编辑: Aditya 提出了一个很好的观点。一些搜索产生了这个有用的提示。