comment controller
:
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create(params[:comment].permit(:comment))
if @comment.save
redirect_to post_path(@post)
else
render 'new'
end
end
index.html.haml
:
#post
= @posts.each do |post|
.post
%p= link_to post.content, post_path(@posts)
.date
%p
published
= time_ago_in_words(post.created_at)
show.html.haml
:
.show
%p= @post.content
.comments
%h2= @post.comments.count
= render @post.comments
%h3= comment to post
= render 'comment/form'
= link_to "edit", edit_post_path(@post)
= link_to "delete", post_path(@post), method: :delete, data: {confirm: "Are you sure?"}
= link_to "home", root_path
答案 0 :(得分:0)
在发布的index.html.haml视图的第二行将=
更改为-
。