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は非常に良い点をもたらします。いくつかの検索で、この役立つヒントが得られました。