Rails 3 中缺少部分错误 [英] Missing Partial Error in Rails 3
本文介绍了Rails 3 中缺少部分错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到一个错误:
Missing partial post/questions, application/questions with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.
Searched in:* "/Users/..../<project name>/app/views"
我尝试将数据库中的所有帖子呈现为 index.html.erb
.
I tried to render all posts in the database to index.html.erb
.
我的视图部分是post/index.html.erb
:
<!--html codes -->
<%= render 'questions' %>
控制器controller/post_controller.rb
:
def index
@posts=Post.all
end
def questions
end
questions.html.erb
<%=@posts.each do |post| %>
<table>
<tr>
<td>
<h2>
<%=post.title%>
</h2>
</td>
</tr>
<tr>
<td>
<h3><%=post.body%></h3>
</td>
</tr>
<tr>
<td>
This Post comes under:<h4><%=post.tag%></h4>
</td>
</tr>
</table>
推荐答案
Partials 的文件名必须以下划线开头.您应该将 _questions.html.erb 保存在 post 文件夹中.此外,您无需定义问题"操作.
Partials' file names must begin with an underscore. You should have _questions.html.erb saved in the post folder. Also, you don't need to define a 'questions' action.
这篇关于Rails 3 中缺少部分错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文