【问题标题】:Jquery datepicker date values does not included into databaseJquery datepicker 日期值不包含在数据库中
【发布时间】:2014-11-27 07:44:41
【问题描述】:

日期值不包含在数据库中

这里是jquery datepicker的代码

 j$(function() {
j$( ".datepicker" ).datepicker();});

表格是

<%= form_for(@leave) do |f| %>



  <%= f.label :start_date %>
  <%= f.datepicker  :start_date , class: 'form-control' %>

  <%= f.label :start_session %>
   <%= f.select :start_session, options_for_select([['Fullday'],['Forenoon'],['Afternoon']]) %>

  <%= f.label :end_date %>
  <%= f.datepicker :end_date, class: 'form-control' %>

  <%= f.label :end_session%>
  <%= f.select :end_session, options_for_select([['Fullday'],['Forenoon'],['Afternoon']]) %>

  <%= f.label :types %>
  <%= f.select :typeof, options_for_select([['Personal'],['Vacation']]) %>

  <%= f.label :no_of_days %>
  <%= f.text_field :no_of_days, class: 'form-control' %>

  <%= f.label :reason %>
  <%= f.text_area :reason_for_leave, class: 'form-control' %>



  <%= f.submit "apply", class: "btn btn-primary" %>
<% end %>

在控制器中

 def create

 @leave = Leave.new(params[:leave])

respond_to do |format|
  if @leave.save
    format.html { redirect_to @leave, notice: 'User was successfully created.' }
    format.json { render json: @leave, status: :created, location: @leave }
  else
    format.html { render action: "apply" }
    format.json { render json: @leave.errors, status: :unprocessable_entity }
  end
end

结束

问题是它不包括列“start_date”和“end_date”的值 这里是日志

    Parameters: {"utf8"=>"✓", "authenticity_token"=>"SnEug2zg76vJ8ShhBQSV6e3UnIrhAV/tDSf8HxDg1xQ=", "
leave"=>{"start_date"=>"11/28/2014", "start_session"=>"Fullday", "end_date"=>"11/29/2014", "end_ses
sion"=>"Fullday", "typeof"=>"Personal", "no_of_days"=>"2", "reason_for_leave"=>"nothing sss"}, "com
mit"=>"apply"}
   (0.1ms)  BEGIN
  SQL (0.4ms)  INSERT INTO "leaves" ("approved", "authorize", "cancel_request", "cancelled", "creat
ed_at", "end_date", "end_session", "no_of_days", "reason_for_leave", "reject_reason", "start_date",
 "start_session", "typeof", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
, $13, $14) RETURNING "id"  [["approved", nil], ["authorize", nil], ["cancel_request", nil], ["canc
elled", nil], ["created_at", Thu, 27 Nov 2014 13:06:25 IST +05:30], ["end_date", nil], ["end_sessio
n", "Fullday"], ["no_of_days", 2.0], ["reason_for_leave", "nothing sss"], ["reject_reason", nil], [
"start_date", nil], ["start_session", "Fullday"], ["typeof", "Personal"], ["updated_at", Thu, 27 No
v 2014 13:06:25 IST +05:30]]
   (1.1ms)  COMMIT

列存储为 nil, 如何解决这个问题?

【问题讨论】:

    标签: jquery ruby-on-rails-3 datepicker


    【解决方案1】:

    使用以#开头的 HTML 控件的 ID,如下所示:

    $("#idCurrentFrom").datepicker();
    

    【讨论】:

      猜你喜欢
      • 2016-03-28
      • 2014-05-04
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      • 2012-06-21
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多