Why is Padrino trying to use a template when rendering a json response?

609 views Asked by At

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?

1

There are 1 answers

1
Camden Narzt On BEST ANSWER

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.