John C
John C

Reputation: 4396

RABL fails for empty query

I have a data tables table which is receiving data via a query that is then formatted using RABL. It all works great until my search finds no rows. Then I just get the ....processing message and no update. I am really confused by RABL. Is there a way to see what it is doing?

This is my data.rabl file

object false

node(:iTotalRecords){@iTotalRecords}
node(:iTotalDisplayRecords){@iTotalDisplayRecords}

child(@aaData, :object_root => false)  do 
  attributes :school_name  => "1",
         :student_name => "3",
         :paid         => "4",
         :short_name   => "5",
         :emailed      => "6",
         :reconciled   => "9"
  node("6") do |p|
    if p.emailed == 0
      'false'
    else
      'true'
    end
  end
  node("0") do |p|
    p.created_at.to_date
  end
  node("2") do |p|
     schedule = p.enrollment.schedule
     link_to(p.klass_name, schedule_path(schedule))
  end
  node("3") do |p|
     link_to(p.enrollment.student.name, student_path(p.enrollment.student_id))
  end
  node("7") do |p|
     p.enrollment.rate
  end
  node("8") do |p|
     p.enrollment.paid
  end
  node("10") do |p|
      link_to("Edit", edit_payment_path(p), :class => 'btn btn-info btn-mini')
  end 
end

Upvotes: 0

Views: 179

Answers (1)

John C
John C

Reputation: 4396

What I needed to do was to make sure that the json included a field called :payments. If there was no data the child loop was not being executed and so there was no reason for RABL to generate a :payments field.

I found that you can force this to happen by creating an alias. So I added the code:

 child :payments => :payments

right before the line

child(@aaData, :object_root => false)  do 

This works great now.

Upvotes: 2

Related Questions