【发布时间】:2017-05-13 19:06:23
【问题描述】:
我试图让它工作,但当我尝试加载页面时显示错误,我试图在帖子下方显示 cmets。
= render post.comments, post: post
上面一行是导致问题并导致错误的那一行,因为找不到模板,它被称为_comment.html.haml。
.posts-wrapper
.post
.post-head
.thumb-img
.user-name
= post.user.user_name
.image.center-block
= link_to (image_tag post.image.url(:medium), class:'img-responsive'), post_path(post)
.post-bottom
.caption
.caption-content
.user-name
= post.user.user_name
= post.caption
.comments{id: "comments_#{post.id}"}
- if post.comments
= render post.comments, post: post
.comment-like-form.row
.like-button.col-sm-1
%span(class="glyphicon glyphicon-heart-empty")
.comment-form.col-sm-11
= form_for [post, post.comments.build] do |f|
= f.text_field :content, placeholder: 'Add a comment...', class: "comment_content", id: "comment_content_#{post.id}"
comment 是 post 中的嵌套路由。
下面是应该渲染的部分文件_comment
.user-name
= comment.user.user_name
.comment-content
= comment.content
- if comment.user == current_user
= link_to post_comment_path(post, comment), method: :delete, data: { confirm: "Are you sure?" }, remote: true do
%span(class="glyphicon glyphicon-remove delete-comment")
路线:
Rails.application.routes.draw do
devise_for :users, :controllers => { registrations: 'registrations' }
resources :posts do
resources :comments
end
root 'posts#index'
end
谢谢
【问题讨论】:
-
你能添加你的路由文件吗?
-
错误信息是什么?
-
@margo ActionView::MissingTemplate in Posts#index 显示 /home/ubuntu/workspace/app/views/posts/_post.html.haml 其中第 17 行出现:缺少部分 cmets/_comment 和 { :locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml, :jbuilder ]}。在以下位置搜索:*“/home/ubuntu/workspace/app/views”*“/usr/local/rvm/gems/ruby-2.3.0/gems/devise-4.2.1/app/views”
标签: ruby-on-rails haml erb