Rails render_to_string 在部分视图中给出错误

发布于 2024-11-30 08:15:15 字数 646 浏览 1 评论 0原文

在代码下方使用带有部分视图的 render_to_string 方法时,我收到 ActionView::MissingTemplate 错误

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

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

但使用普通视图的 render_to_string 在同一项目中工作得很好。可能是什么原因?

在堆栈跟踪下方

ActionView::MissingTemplate(缺少部分商家/biz_new {: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”):

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)

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

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

below the stack trace

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"):

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

森林很绿却致人迷途 2024-12-07 08:15:15

尝试

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

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

Try

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

render_to_string needs the starting underscore and the .html extension.

稳稳的幸福 2024-12-07 08:15:15

正如 Mike Kijewski 提到的,您可以在部分名称的开头包含下划线,但如果您最后使用 .html,您将收到弃用警告。更直接的方法是这样的:

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

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})
日裸衫吸 2024-12-07 08:15:15

看起来 Rails 期望文件采用 txt 格式。文件名为什么?尝试命名它:

_biz_new.txt.erb 

-或-

businesses/_biz_new.txt.erb

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
你爱我像她 2024-12-07 08:15:15

我在使用 formats: "html" 但需要更改为 formats: :html 之类的符号时遇到了问题。

I had a problem where I was using formats: "html" but needed to be changed to a symbol like formats: :html.

冰葑 2024-12-07 08:15:15

有类似的问题。

我找到了一个解决方案:

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

Had similar issue.

I found a solution:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文