rails render_to_string 给出部分视图错误 [英] rails render_to_string giving errors with partial view

查看:71
本文介绍了rails render_to_string 给出部分视图错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在代码下方使用带有部分视图的 render_to_string 方法时出现 ActionView::MissingTemplate 错误

I am getting ActionView::MissingTemplate error when using render_to_string method with partial views, below the code

 bizz = render_to_string(:partial => "biz_new",:layout => false)

即使我已经明确指定了 :layout =>false,我总是收到 MissingTemplate 错误.

Even though i have explicitly specified :layout => false, i am getting the MissingTemplate error always.

但是使用普通视图的 render_to_string 在同一个项目中工作正常.可能是什么原因?

But render_to_string with normal views works fine in the same project. what could be the reason?

在堆栈跟踪下方

ActionView::MissingTemplate (Missing partial business/biz_new with{:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:text,"/"], :locale=>[:en, :en]} 在视图路径中"/home/ramesh/works/xxx/app/views",/home/ramesh/works/xxx/vendor/plugins/asset_packager/app/views"):

ActionView::MissingTemplate (Missing partial businesses/biz_new with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:text, "/"], :locale=>[:en, :en]} in view paths "/home/ramesh/works/xxx/app/views", "/home/ramesh/works/xxx/vendor/plugins/asset_packager/app/views"):

推荐答案

尝试

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

render_to_string 需要起始下划线和 .html 扩展名.

render_to_string needs the starting underscore and the .html extension.

这篇关于rails render_to_string 给出部分视图错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆