如何在 Rails 中渲染视图 [英] How to render view in rails
问题描述
我正在为我的应用程序使用 rails.我已经为 crud 操作生成了脚手架.我有 product_lists 的脚手架.我有一个名为 user_dashboard.html.erb 的页面,我想从 product_lists 呈现页面.
我在 pages/
目录中有 user_dashboard.html.erb
页面..我想从 user_dashboard.html 内的 product_lists 目录呈现 index.html 页面.erb
.我试过使用渲染..但它的显示错误这是我尝试过的
<%= 渲染 'product_lists' %>
错误:
ActionView::MissingTemplate in Pages#user_dashboard
我该如何解决这个错误,为什么会出现这个错误?
它不是部分(以下划线开头),所以你需要渲染模板.您还需要模板的完整路径,来自视图目录:
<%= 渲染模板:'product_lists/index' %>
i am using rails for my application.i have generated scaffold for crud operation. i have scaffold for product_lists. i have page called user_dashboard.html.erb here i want to render pages from product_lists.
i have user_dashboard.html.erb
page in pages/
directory..i want to render index.html page from product_lists directory inside user_dashboard.html.erb
. i have tried using render.. but its showing error
here is what i have tried
<div class="panel-body">
<%= render 'product_lists' %>
</div>
error:
ActionView::MissingTemplate in Pages#user_dashboard
How can i solve this error and why is this raised?
It is not a partial (starts with underscore), so you need render template. You also need the full path of the template, from the view directory:
<%= render template: 'product_lists/index' %>
这篇关于如何在 Rails 中渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!