ruby-on-railscalendarpickadate

pickadate does not show a disable days in my ror application


I am having a problem with pickadate component in my rails application. I am not able to disable days in calendar.

I'm loading a disable dates in my model in this function:

  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

result of this function:

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

and my javascript looks like this:

- 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: '' 
     })
   });

Any suggestions ?


Solution

  • I was update my busy_days function and it works now