I’m trying to generate a JSON response that includes some HTML. Thus, I have /app/views/foo/bar.json.erb:
{ someKey: 'some value', someHTML: '<%= h render(:partial => '/foo/baz') -%>' }
I want it to render /app/views/foo/_baz.html.erb, but it will only render /app/views/foo/_baz.json.erb. Passing :format => 'html' doesn’t help.
Building on roninek’s response, I’ve found the best solution to be the following:
in /app/helpers/application.rb:
In /app/views/foo/bar.json:
An alternate solution would be to redefine
renderto accept a:formatparameter.I couldn’t get
render :fileto work with locals and without some path wonkiness.