【问题标题】:Missing Partial Error in Rails 3Rails 3 中缺少部分错误
【发布时间】:2012-06-08 05:58:24
【问题描述】:

我收到一个错误:

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>

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    Partials 的文件名必须以下划线开头。您应该将 _questions.html.erb 保存在 post 文件夹中。此外,您无需定义“问题”操作。

    【讨论】:

    • 有类似的问题...忘记了 .html.erb 扩展名。 .rb 不起作用大声笑
    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 2021-10-24
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多