开发者

Partial rendering one time too many for collection

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.commen开发者_高级运维ts.build])


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜