开发者

Partial rendering one time too many for collection

开发者 https://www.devze.com 2023-04-12 06:17 出处:网络
Creating a simple blog application, I have this partial .comment %p %b Namn: = comment.name %p %b kommentar: = comment.content

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

精彩评论

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