json erb template cannot find other html partial

前端 未结 4 1226
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:14

    I'm not sure if I got you right, but maybe you can play with the content type like this:

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

    The :locals is just if you want to pass an var to the partial.

提交回复
热议问题