Rails 3中的"Missing Partial"错误

6
我正在遇到一个错误:
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中。

我的视图部分是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>
1个回答

17

局部文件名必须以下划线开头。您应该将_questions.html.erb保存在post文件夹中。另外,您不需要定义“questions”操作。


遇到了类似的问题......忘记了.html.erb扩展名。 .rb行不通哈哈 - Jan Hettich

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接