How do I render a partial of a different format in Rails?

前端 未结 11 1257
执念已碎
执念已碎 2020-11-28 04:21

I\'m trying to generate a JSON response that includes some HTML. Thus, I have /app/views/foo/bar.json.erb:

{
  someKey: \'some value\',
  someH         


        
11条回答
  •  天涯浪人
    2020-11-28 05:08

    It seems that passing a formats option will render it properly in newer Rails version, at least 3.2:

    {
      someKey: 'some value',
      someHTML: "<%= h render('baz', formats: :html) -%>"
    }
    

提交回复
热议问题