pickadate在我的ror应用程序中没有显示禁用日期

时间:2018-04-07 19:47:41

标签: ruby-on-rails calendar pickadate

我的rails应用程序中的pickadate组件出现问题。我无法在日历中禁用日期。

我在这个函数中加载了模型中的禁用日期:

  def busy_days
    days = []
    reservations.each do |reservation|
      reservation_start = ( reservation.reservation_start_date - 1.month)
      reservation_end = ( reservation.reservation_end_date - 1.month)
      days << "{ from: [#{reservation_start.strftime("%Y,%-m,%d")}], to: [#{reservation_end.strftime("%Y,%-m,%d")}]}"
    end
    days.join(",")
  end

此功能的结果:

{ from: [2018,3,13], to: [2018,3,14]},{ from: [2018,3,12], to: [2018,3,13]},{ from: [2018,3,07], to: [2018,3,10]} 

我的javascript看起来像这样:

- if @subject.reservations.present?
  %script
    var datesToDisable = ["#{@subject.busy_days}"]
    $(document).ready(function() { 
      $('.datepicker').pickadate({ 
       formatSubmit: 'yyyy/mm/dd',
       hiddenSuffix: '',
       disable: datesToDisable , 
       min: Date.now()
     })
   });
-  else
  %script
    $(document).ready(function() { 
     $('.datepicker').pickadate({ 
      formatSubmit: 'yyyy/mm/dd',
      hiddenSuffix: '' 
     })
   });

有什么建议吗?

1 个答案:

答案 0 :(得分:-1)

我正在更新我的busy_days函数,现在可以正常使用