0
我正在构建一个blogapp,并允许用户使用其名称对帖子发表评论,如果用户未登录,它将显示为anonamys。它的工作,但在我的浏览器,它显示了一个充满评论数组。我如何摆脱这一点。在我评论控制器在我的博客应用程序中显示一组消息
def create
params.permit!
@post = Post.find(params[:post_id])
@comment.user_id = current_user.id if current_user || nil
@comment.save
redirect_to post_path(@post)
end
在形式部分的意见
<%= form_for [@post, @post.comments.build] do |f| %>
在我帖子控制器显示行动
<h4><%= @post.comments.count %> Comments</h4>
<%= render partial: "comments/comment" %>
<%= render partial: "comments/form" %>
而在我的评论部分我有
<%= @post.comments.each do |comment| %>
<p class="comment_name"><strong><%= (comment.user.user_name if comment.user) || "Anonymous" %></strong></p>
<p class="comment_body"><%= comment.body %></p>
<p class="comment_time"><%= time_ago_in_words(comment.created_at) %> Ago</p>
在浏览器中的阵列消息被示出作为
[#<Comment id: 13, name: nil, body: "nice pic", post_id: 17, created_at: "2015-09-27 20:54:22", updated_at: "2015-09-27 20:54:22", user_id: 8>, #<Comment id: 14, name: "sss", body: "sssss", post_id: 17, created_at: "2015-09-27 21:41:13", updated_at: "2015-09-27 21:41:13", user_id: nil>]
我不知道其中发生错误。提前致谢。
这是有效的。感谢Pavan, – Vikram