{&#34; ID&#34; = GT;&#34;#<交:: activerecord_relation:0x7428828>&#34;}

时间:2015-07-30 23:28:04

标签: ruby-on-rails

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

1 个答案:

答案 0 :(得分:0)

在发布的index.html.haml视图的第二行将=更改为-