【问题标题】:ActionView::MissingTemplate in Posts#showActionView::MissingTemplate in Posts#show
【发布时间】:2014-08-08 21:25:57
【问题描述】:

我正在http://www.reinteractive.net/posts/32-ruby-on-rails-3-2-blog-in-15-minutes-step-by-step 的帮助下创建一个博客。添加新的博客文章非常棒,但每次我想发表新评论时都会收到以下错误:

<h2>Comments</h2>
<div id="comments">
        <%= render :partial => @post.comments %>
</div>

<%= form_for [@post, Comment.new] do |f| %>

我得到的错误:

ActionView::MissingTemplate in Posts#show 
Missing partial comments/_comment with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
  * "/Users/Reuzellf/quick_blog/app/views"

Ruby 对我来说是全新的,我真的不知道如何解决这个问题。

【问题讨论】:

  • 我没有看到任何错误。
  • 对不起,我很快就发布了
  • 似乎有问题: @post.cmets %>
  • 您是否在您附加的 link 中看到了这一行 You'll now need to create a file called app/views/comments/_comment.html.erb with the following contents

标签: ruby-on-rails ruby actionview


【解决方案1】:

这是简写。

Rails 将在这种情况下查看对象 Comment 并转到该对象的视图。

在这种情况下,它将在 app/views/comments 中查找名为 _comment.html.erb 的部分

因此,如果 cmets 目录不存在,则创建该目录,然后使用您希望每个评论显示的任何内容创建部分目录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多