1
votes

Im trying to get this to work but it shows up an error when I try and load the page, im trying to show comments below posts.

= render post.comments, post: post 

The line above is the one causing the problem and causing an error because the template cannot be found, its called _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 is a nested route inside post.

Below is the partial file _comment that is supposed to be rendered

    .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")

Routes:

    Rails.application.routes.draw do
  devise_for :users, :controllers => { registrations: 'registrations' }  

  resources :posts do 
    resources :comments
  end

  root 'posts#index'

end

Thanks

1
Can you add your routes file please. - hashrocket
what's the error message? - margo
@margo ActionView::MissingTemplate in Posts#index Showing /home/ubuntu/workspace/app/views/posts/_post.html.haml where line #17 raised: Missing partial comments/_comment with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml, :jbuilder]}. Searched in: * "/home/ubuntu/workspace/app/views" * "/usr/local/rvm/gems/ruby-2.3.0/gems/devise-4.2.1/app/views" - C.White

1 Answers

0
votes

The way I see it, Rails can't find your _comments partial. I guess you placed it somewhere where it doesn't belong.

your views structure should look something like this:

views
  comments
    _comment.html.haml
  posts
    _post.html.haml

_comment.html.haml has to be in the comments folder.