1

我在我的应用程序中使用了无数次单选按钮,但从未遇到过这个问题,所以我假设我没有注意到一个非常愚蠢的错误。该表单可以很好地提交所有其他模型的属性,但是由于某种原因, :referral_type 只是没有显示在服务器输出的参数中,当然也没有保存到数据库中。

= 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="&#x2713;" /><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>

我期待你们中的一个人指出我的疏忽,谢谢!

4

1 回答 1

0

在搞砸了 4 天后,我发现了这个问题。根据:https://code.google.com/p/chromium/issues/detail?id=244645,这是 Chrome 自动填充在某些情况下删除单选按钮和复选框的检查的错误。禁用自动填充解决了这个问题。它应该在 Chrome v28 中修复(我目前使用的是版本 27.0.1453.116)。希望这可以节省一些时间。

于 2013-07-01T16:45:39.210 回答