Rails 缺少模板错误 (haml)
Rails error missing template (haml)
我试图让它工作,但是当我尝试加载页面时它显示错误,我试图在 posts 下面显示评论。
= 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
谢谢
依我看,Rails 找不到您的 _comments 部分内容。我猜你把它放在了不属于它的地方。
您的视图结构应如下所示:
views
comments
_comment.html.haml
posts
_post.html.haml
_comment.html.haml 必须在评论文件夹中。
我试图让它工作,但是当我尝试加载页面时它显示错误,我试图在 posts 下面显示评论。
= 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
谢谢
依我看,Rails 找不到您的 _comments 部分内容。我猜你把它放在了不属于它的地方。
您的视图结构应如下所示:
views
comments
_comment.html.haml
posts
_post.html.haml
_comment.html.haml 必须在评论文件夹中。