不显示评论我认为此事在视野中,但我无法理解错误在哪里
这是截图
我的github https://github.com/astrsky/recipe
配方/应用/视图/评论/ _comments.html.erb
<h3>Comments</h3>
<% commentable.comments.each do |comment| %>
<div class = "well">
<% comment.body %>
</div>
<% end %
配方/应用/视图/评论/ _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 %>
配方/应用/视图/食谱/ 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
-@recipe.ingredients.each 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
答案 0 :(得分:3)
你错过了=
。它应该是:
<%= comment.body %>