Ruby 简单表单复选框在 True 时不检查

Ruby Simple Form Checkbox not checking when True

所以我使用简单的形式 Ruby Gem 制作了多个复选框。但问题是,即使我检查并设置它们 "true" 并按下更新按钮,它们也没有显示出来。我有三个例子,它们都不起作用,我已经尝试为所有三个做不同的代码。

  <%= f.input :same_as_client_email,
              inline_label: "Same as Client Email",
              as: :boolean %>

第一个例子

<%= f.input :same_as_client_name,
    inline_label: "Same as Client Name",
    as: :boolean,  checked_value: true,unchecked_value: false
    %>

第二个例子

<%= f.input :active,
    as: :boolean,
    checked_value: true, unchecked_value: false,
    input_html: { value: '1', checked: true },
    inline_label: "Active"%>

最后一个例子。

None 这些实际工作或保持检查。我有其他输入,当我按下更新按钮时它们正在保存。但是复选框不是。任何帮助将不胜感激。

这是一个 javascript 问题,以防其他人看到这个问题。一起使用 jquery 和 simpleform 时要小心。我的问题是我们有 jquery 代码来使我们的按钮更美观。

//$(function checkbox() {
//  'use strict'
//
//  var originalElement = $('input[type="checkbox"]');
//  var overlay = '<div class="checkbox-overlay"><div class="inner"></div></div>';
//
//  function swapCheckbox() {
//    originalElement.replaceWith(overlay);
//  }
//
//  function toggleCheckbox() {
//    $(this).toggleClass('checked');
//
//  }
//
//  function initialize() {
//    swapCheckbox();
//    $('body .checkbox-overlay').on('click', toggleCheckbox);
//  }
//
//  initialize();
//});

但实际上,这使得它变得如此简单,只接收 0 而从不接收 1。换句话说,即使您选中了该框,它也永远不会真正起作用,因为此 Jquery 代码在将变量发送到 simpleform 时对其进行了操作。将来我会更新这个 post 如果我修复了复选框,这样它们看起来 "pretty" 而不会弄乱功能。这个问题花了很长时间才解决,考虑到我不知道这个文件,直到一个 SimpleForm 开发人员指出他们可能是一个混淆我的代码的 js 文件。

编辑:我希望这能更好地解释问题!