Argument out of range Rails 4 and bootstrap3-datetimepicker-rails

后端 未结 4 745
隐瞒了意图╮
隐瞒了意图╮ 2021-02-07 08:29

I\'m using the bootstrap3-datetimepicker-rails gem to let users store the scheduled_date of a WorkOrder in my application (a \'DateTime\' property), bu

4条回答
  •  天涯浪人
    2021-02-07 09:07

    @Uri Agassi is right: it's the values that you're passing to create the WorkOrder that are the most relevant here.

    Try putzing around with the custom date formatting options provided to you by bootstrap-datepicker. If you can get a format that looks good and is easy to parse on the backend, then you'll want to intercept that parameter before it goes to the model for validation.

    Regardless of what you'll go with for date formatting on the client-side, you'll still want to parse it into a useable Date or DateTime object server-side in your controller. Check out DateTime#strptime. You can also call #strptime on Date.

    Untested, but the idea is there:

    def create
      order_params = work_order_params
      order_params[:scheduled_date] = Date.strptime(order_params[:scheduled_date],
                                                    '%m/%d/%Y %I:%M %p')
      @work_order = WorkOrder.new(order_params)
    end
    

提交回复
热议问题