Rails简单表单不提交

时间:2014-01-19 11:09:28

标签: ruby-on-rails simple-form

当我添加这两个字段时,我在导轨中使用simple_form_for帮助程序构建了一个表单,但未提交,

<%=f.input :startDate, :as => :datetime_picker%>
<%=f.input :endDate, :as => :datetime_picker%>

这个javascript:

<script type="text/javascript">
  $(function() {
    $('#datetimepicker1').datetimepicker({
      language: 'en'
    });
    $('#actioncustom_timezone').set_timezone({format: 'city'});
    $("#actioncustom_timezone").select2({ width: "300px" });
  });
</script>

当我在表单中有这两个字段时,单击提交,视图不会呈现失败。当我删除这两个字段时,表单会完美呈现,甚至会显示错误。

日期字段有什么特别之处,当我添加它们时,它们会破坏我的表单?

编辑:所有表单代码:

<h1>New Custom Action</h1>

<div class="row">
<div class="span6 offset3">
    <%= simple_form_for(@actionCustom) do |f|%>
    <%= render 'shared/error_messages' %>

    <%=f.label :action_name%>
    <%=f.text_field :action_name%></br>

    <%=f.label :contentURL, "Content URL"%>
    <%=f.text_field :contentURL%></br>

    <%=f.label :callBackURL, "Callback URL"%>
    <%=f.text_field :callBackURL%></br>

    <%=f.label :customcallbackURL, "Callback URL with custom conent URL"%>
    <%=f.text_field :customcallbackURL%></br>

    <%=f.label :previewImageURL, "Preview image URL"%>
    <%=f.text_field :previewImageURL%></br>

    <%=f.date_ :startDate, :as => :datetime_picker%>
    <%=f.input :endDate, :as => :datetime_picker%>

    <%=f.label :timezone, "Timezone"%>
    <%=f.time_zone_select :timezone%>

    <%=f.label :message%>
    <%=f.text_area :message%></br>

    <%=f.label :maxSend, "Max number of all sendings"%>
    <%=f.number_field :maxSend, options = {:min=>0,:value=>0}%></br>

    <%=f.label :maxSendToday, "Max number of sendings per day"%>
    <%=f.number_field :maxSendToday, options = {:min=>0,:value=>0}%></br>

    <%=f.label :maxSendDevice, "Max number of sendings per device"%>
    <%=f.number_field :maxSendDevice, options = {:min=>0,:value=>0}%></br>

    <%=f.label :maxSendDeviceToday,"Max number of sendings per device per day"%>
    <%=f.number_field :maxSendDeviceToday, options = {:min=>0,:value=>0}%></br>


    <%=f.hidden_field :clientID, :value => current_client.id%>

    <%= f.submit "Create Action", class: "btn btn-large btn-primary" %>

    <%end%>
</div>
 </div>

   <script type="text/javascript">
   $(function() {
   $('#datetimepicker1').datetimepicker({
  language: 'en'
  });
  $('#actioncustom_timezone').set_timezone({format: 'city'});
  $("#actioncustom_timezone").select2({ width: "300px" });
});
</script>

2 个答案:

答案 0 :(得分:0)

你使用的是这个宝石https://github.com/zpaulovics/datetimepicker-rails吗?

如果您使用的是rails4,则可以使用新的 date_field ,即使用新的HTML5选择器。 使用此解决方案,您无需使用jQuery datetimepicker。

如果您不使用rails4,您只需将输入类型设置为日期日期时间,如

<input id="user_born_on" name="user[born_on]" type="datetime" />

您将获得HTML5浏览器的选择器。

enter image description here

我在这里为您创建了一个示例代码:http://jsfiddle.net/2NAL5/

有关此内容的更多信息:http://blog.remarkablelabs.com/2012/12/new-html5-form-input-helpers-rails-4-countdown-to-2013

答案 1 :(得分:0)

所以我解决了我的问题。我发现在HTML代码中,日期时间输入是根据需要设置的。因此,当该字段为空时,我无法提交表单。但是在将日期时间线修改为:

之后
        <%=f.input :startDate,:as => :datetime_picker,:required => false%>

它有效!!!!!

相关问题