【问题标题】:storing data from checkboxes to database in rails将数据从复选框存储到rails中的数据库
【发布时间】:2012-07-02 19:46:39
【问题描述】:
<script>
  function checkValue(){
     var checkboxes = $("input[type='checkbox']");

     if ( $('#student').val() == ""  ) {
        alert('Please select any student!');
        return false;
     }
     else {
        if(checkboxes.is(":checked")) {
           return true;
        }
     }

我的复选框工作正常;我需要知道如何处理它,以便将复选框的值存储到 DB。

【问题讨论】:

  • 你的问题不是很清楚。你想在数据库中存储什么?你的表是如何构成的?您想存储#student 价值吗?

标签: ruby-on-rails checkbox


【解决方案1】:

您可以使用以下方法之一:

<%= form_for :model %>
  <% f.check_box :field_name %>
<% end %>

或者

<%= form_for :model %>
  <% check_box_tag :model_field_name %>
<% end %>

【讨论】:

    【解决方案2】:

    根据您的需要使用simple_form。它非常受欢迎,并且建立在 formtastic 之上。

    详情请见https://github.com/plataformatec/simple_form/

    您还可以在以下位置查看出色的实现细节:http://railscasts.com/episodes/234-simple-form

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 2013-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多