Илья Коган
Илья Коган

Reputation: 15

does not display comments rails

does not display comments I think the matter is in view, but I can not understand where the error

here is a screenshot

enter image description here

My github https://github.com/astrsky/recipe

recipe/app/views/comments/_comments.html.erb

<h3>Comments</h3>
<% commentable.comments.each do |comment| %>
  <div class = "well">
    <% comment.body %>
    </div>
<% end %

recipe/app/views/comments/_form.html.erb

<%= form_for [commentable, Comment.new] do |f| %>
  <div class = "form-group">
    <%= f.text_area :body, class: "form-control", placeholder: "Add a comment" %>
  </div>
  <%= f.submit class: "btn btn-primary" %>
<% end %>

recipe/app/views/recipes/show.html.haml

ain_content
  #recipe_top.row
    .col-md-4
      = image_tag @recipe.image.url(:medium), class: "recipe_image"
    .col-md-8
      #recipe_info
        %h1= @recipe.title
        %p.description= @recipe.description

  .row
    .col-md-6
      #ingredients
        %h2 Ingredients
        %ul
          [email protected] do |ingredient|
            %li= ingredient.name

    .col-md-6
      #directions
        %h2 Directions
        %ul
          - @recipe.directions.each do |direction|
            %li= direction.step

  .row
    .col-md-8
      #Commets
       
        %ul
          = render partial: "comments/comments", locals: {commentable: @recipe}
          = render partial: "comments/form", locals: {commentable: @recipe}

  .row
    .col-md-12
      = link_to "Назад", root_path, class: "btn btn-default"
      -if user_signed_in?
        = link_to "Изменить", edit_recipe_path, class: "btn btn-default" 
= link_to "Удалить", recipe_path, method: :delete, data: {confirm: "Are you sure?"}, class: "btn btn-default" 

recipe/app/controllers/comments_controller.rb

class CommentsController < ApplicationController
  before_action :authenticate_user!

  def create
    @comment = @commentable.comments.new comment_params
    @comment = current_user
    @comment.save
      redirect_to @commentable, notice: "Your comment was successfully posted."
  end



  private
    def comment_params
      params.require(:comment).permit(:body)
    end
end

Upvotes: 0

Views: 60

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51151

You miss =. It should be:

<%= comment.body %>

Upvotes: 3

Related Questions