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

前端 未结 11 1254
执念已碎
执念已碎 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:09

    I came across this thread when I was trying to render an XML partial in another xml.builder view file. Following is a nice way to do it

    xml.items :type => "array" do
        @items.each do |item|
            xml << render(:partial => 'shared/partial.xml.builder', :locals => { :item => item })
        end
    end
    

    And yeah... Full file name works here as well...

提交回复
热议问题