json erb template cannot find other html partial

前端 未结 4 1299
Happy的楠姐
Happy的楠姐 2021-01-02 06:41

I am trying to have a json response in which some value is html rendered by a partial

#projects_Controller.rb

def index
  respond_to do |f|
    f.json 
  en         


        
4条回答
  •  [愿得一人]
    2021-01-02 07:01

    Got it: All one needs is this line in the .json.erb file <% self.formats = ["html"] %>

    So the full index.json.erb

          <% self.formats = ["html"] %>
          disclaimer = {
            "html":"<%= raw escape_javascript(render :partial => 'projects/disclaimer',
                        :content_type => 'text/html'), 
                        :locals => {:localVariable => @localVariable} 
                    %>"
          }
    

提交回复
热议问题