2

I am using RABL for formatting a JSON API response. However, I would like to use that same JSON and render it inline in a different view to use with some JavaScript. Essentially, I'd like to do:

var my_model_data = #{@model.to_json}

...but use the RABL template instead of calling to_json.

How can I achieve this?

Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

1

I found a way to do it, based on this wiki post.

Instead of:

@model.to_json

You can do this:

render(file: 'foo/bar', object: @model, formats: :json).html_safe
Andrew
  • 227,796
  • 193
  • 515
  • 708