0

I have adopted a padrino application [repo], and am looking to move all the data into a json returned ajax call. From googling around I've seen:

So I created this method/response to try and start moving the data to a separate response:

get :data, provides: :json do
  @records = Record.order(:day).all
  render @records, layout: false
end

This results in a template not found error:

Padrino::Rendering::TemplateNotFound at /data.json
Template '#<Record:0x007fd19decdeb8>' not found in '~/Developer/Ruby/arewesmallyet/app/views'

and

Padrino::Rendering::TemplateNotFound at /data
Template '#<Record:0x007fd19decdeb8>' not found in '~/Developer/Ruby/arewesmallyet/app/views'

which doesn't make sense, obviously I don't want to use a template here, so what am I missing?

Community
  • 1
  • 1
Camden Narzt
  • 2,271
  • 1
  • 23
  • 42

1 Answers1

2

So I got it to work by replacing render @records, layout: false with @records.to_json.

Pretty sure that's not how it's supposed to work, so if anyone knows a better way I'm all ears, otherwise I'll accept this answer.

Camden Narzt
  • 2,271
  • 1
  • 23
  • 42
  • I am also new to Padrino. I have been following the to_json approach to pass the json response. If there is any error, I would use halt method with the error code and return json. Just go through halt method. I couldnt find any other way to render json. – Deepak A Nov 17 '14 at 17:48