我在我的应用程序中无数次使用了单选按钮,从未遇到过这个问题,所以我假设我忘记了一个非常愚蠢的错误。表单提交所有其他模型的属性就好了,但由于某种原因,: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>
我期待你们中的一位指出我的忽视,谢谢!
答案 0 :(得分:0)
经过4天的捣乱,我发现了这个问题。根据:https://code.google.com/p/chromium/issues/detail?id=244645,在某些情况下,Chrome自动填充功能会删除单选按钮和复选框的检查,这是一个错误。禁用自动填充修复了该问题。它应该在Chrome v28中修复(我目前使用的是版本27.0.1453.116)。希望能节省一些时间。