0

Creating a simple blog application,

I have this partial

.comment
%p
    %b 
        Namn:
        = comment.name

%p
    %b
        kommentar:
        = comment.content


%p
    = link_to 'Destroy Comment', [comment.post, comment],
            :confirm => 'Are you sure?',
            :method => :delete

and its called from

= render :partial => 'comment', :collection => @post.comments

it always renders the partial one time to many?

edit:

It has this form

= form_for ([@post,@post.comments.build])
skyw00lker
  • 819
  • 9
  • 20

1 Answers1

0

As depicted in the comments of your question, the @post.comments.build is the culprit. Change it to

= form_for ([@post, @post.comments.new])

and the additional item when rendering the collection should be gone.

There is a good post about the difference of build and new here: Build vs new in Rails 3

Community
  • 1
  • 1
emrass
  • 6,253
  • 3
  • 35
  • 57