2015-10-20 100 views
1

我在app/pdfs/templates/work文件夹中有一些pdf模板,并且在其中的每个代码中都有一些代码在重复,我想用此代码添加一个局部和渲染它在模板中。如何在Rails中渲染自定义模板中的部分

<td class="money last footer-subtotal"> 
    <p><strong><%= sub_total %></strong></p> 
    <p><strong><%= total_tax %></strong></p> 
    <p class="footer-total"><strong><%= final_price %></strong></p> 
</td> 

在模板中我使用:

我在app/PDF文件/模板/ _calculation.html.erb添加parrtial

<%= render "templates/calculation" %> 

当我点击PDF,我得到以下错误:

未定义的方法`呈现”为#

+0

我没有用之前的PDF文件的工作 - 你是如何将它们输出到视图? –

+0

或者如何在助手方法中写上述代码 – venkat

回答

1

部分阅读应用程序/视图。

而不是把你的部分上:

app/pdfs/templates/

将意见里面:

app/views/pdfs/templates/

+0

我做了同样的事情,并给出了<%= render“/ pdfs/templates/calculation”%>',但同样的错误。 – venkat

+0

删除pdf之前的''/''。并确保它在app/views下。 (app/views/pdfs/templates/_calculation.html.erb)然后你可以调用它为:'<%= render'pdfs/templates/calculation'%>' – 2015-10-20 08:29:48

+0

它没有帮助我。同样的问题 – venkat