rails render_to_string giving errors with partial view

被刻印的时光 ゝ 提交于 2019-12-05 14:53:17
Mike Kijewski

Try

 render_to_string("_biz_new", :formats => [:html], :layout => false, :locals => {:biz => @biz})

render_to_string needs the starting underscore and the .html extension.

As Mike Kijewski mentioned, you can include the underscore at the beginning of the partial name, but if you use the .html in the end you will get a deprecation warning. A more straightforward way is this:

render_to_string(:partial => "folder_name/_partial_name", :formats => [:html], :layout => false, :locals => {:a_needed_argument_for_the_partial => @arg})

It looks like rails is expecting the file to be in format txt. What's the file named ? Try naming it:

_biz_new.txt.erb 

-or-

businesses/_biz_new.txt.erb

Had similar issue.

I found a solution:

render_to_string(model, :formats => [:html])

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!