Jquery datepicker日期值未包含在数据库中

时间:2014-11-27 07:44:42

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

日期值未包含在数据库中

这是代码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, 如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

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

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