Reputation: 239087
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?
Upvotes: 2
Views: 359
Reputation: 239087
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
Upvotes: 1