且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Rails 中渲染视图

更新时间:2023-09-28 14:37:22

它不是部分(以下划线开头),所以你需要渲染模板.您还需要模板的完整路径,来自视图目录:

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' %>