Search code examples
ruby-on-railsrubyjsonrabl

Rabl undefined method error


I am getting a "undefined method `iso8601' for nil:NilClass" error for my rabl view

view:

collection @appointments
attributes :id
node(:start) { |appointment| appointment.start.iso8601}
node(:end) { |appointment| appointment.finish.iso8601}
node(:title) { |appointment| '<a class="patient-select-link" data-id="'+appointment.patient.id.to_s+'">'+appointment.patient.full_name+'</a>' }

controller:

@appointments = Appointment.order("id DESC")

I can't work out where ive gone wrong! I copied the rabl github page example almost exactly, whatever I do the appointment variable is never defined, although I can confirm that @appointments is defined (bettererrors) and has the correct data


Solution

  • It seems to be One of your appointment object does not have start. I mean the value is nil. That's why it is showing an error.