私は自分のアプリでラジオ ボタンを数え切れないほど使用してきましたが、この問題を経験したことはありません。フォームは他のすべてのモデルの属性を問題なく送信しますが、何らかの理由で、:referral_type がサーバー出力の params に表示されず、もちろん db に保存されません。
= form_for(@writer, :html => { :class => "user_new", :id => "user_new" }) do |f|
- unless @writer.approved?
.field.divider
%label How did you hear about us?
.writer-channel-input-container
= f.radio_button :referral_type, "Searching Google"
= f.label :referral_type, "Searching Google", value: "Searching Google"
.writer-channel-input-container
= f.radio_button :referral_type, "CraigsList"
= f.label :referral_type, "CraigsList", value: "CraigsList"
.writer-channel-input-container
= f.radio_button :referral_type, "FlexJobs"
= f.label :referral_type, "FlexJobs", value: "FlexJobs"
.writer-channel-input-container.referral-detail
= f.radio_button :referral_type, "A Forum"
= f.label :referral_type, "A Forum", value: "A Forum"
.writer-channel-input-container.referral-detail
= f.radio_button :referral_type, "A Friend"
= f.label :referral_type, "A Friend", value: "A Friend"
.writer-channel-input-container.referral-detail
= f.radio_button :referral_type, "Other"
= f.label :referral_type, "Other", value: "Other"
.referral-detail-input-container{ hidden: "hidden" }
= f.text_field :referral_detail, disabled: "disabled", placeholder: "Please specify..."
次の html が生成されますが、これは意図したとおりのようです。
<form accept-charset="UTF-8" action="/writers" class="user_new" id="user_new" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="fWmxanHllFr0ufsxjEeZSKT6UQyRrLarIB/HOqWLxDA=" /></div>
<div class='field divider'>
<label>How did you hear about us?</label>
<div class='writer-channel-input-container'>
<input id="writer_referral_type_searching_google" name="writer[referral_type]" type="radio" value="Searching Google" />
<label for="writer_referral_type_searching_google">Searching Google</label>
</div>
<div class='writer-channel-input-container'>
<input id="writer_referral_type_craigslist" name="writer[referral_type]" type="radio" value="CraigsList" />
<label for="writer_referral_type_craigslist">CraigsList</label>
</div>
<div class='writer-channel-input-container'>
<input id="writer_referral_type_flexjobs" name="writer[referral_type]" type="radio" value="FlexJobs" />
<label for="writer_referral_type_flexjobs">FlexJobs</label>
</div>
<div class='writer-channel-input-container referral-detail'>
<input id="writer_referral_type_a_forum" name="writer[referral_type]" type="radio" value="A Forum" />
<label for="writer_referral_type_a_forum">A Forum</label>
</div>
<div class='writer-channel-input-container referral-detail'>
<input id="writer_referral_type_a_friend" name="writer[referral_type]" type="radio" value="A Friend" />
<label for="writer_referral_type_a_friend">A Friend</label>
</div>
<div class='writer-channel-input-container referral-detail'>
<input id="writer_referral_type_other" name="writer[referral_type]" type="radio" value="Other" />
<label for="writer_referral_type_other">Other</label>
</div>
<div class='referral-detail-input-container' hidden='hidden'>
<input disabled="disabled" id="writer_referral_detail" name="writer[referral_detail]" placeholder="Please specify..." size="30" type="text" />
</div>
私の見落としを指摘してくれるのを楽しみにしています、ありがとう!