Ruby on Rails Wednesday, December 1, 2010

Hi,

I'm not sure why you are worried about touching the data store.
collection.build doesn't save the new object so there is nothing in
the db that could be deleted.
If all you want to do is revert collection.build just remove that
element of the association array (as pepe pointed out).

comment = @post.comments.build
@post.comments.delete(comment)

or

@post.comments.build
@post.comments.delete(@post.comments.last)

Hope this helps!

Simon

On Nov 30, 9:13 pm, Lille <lille.pengu...@gmail.com> wrote:
> Hi,
>
> My Rails app offers opportunities to try out models on a 'what-if'
> basis, where dependent associations can be modified to obtain
> alternative results for the parent. Is there a way to delete/destroy
> the member of a collection so that I can play around with the
> accordingly modified parent in memory, without actually committing the
> destruction of the collection member to the data store? Based on my
> read of the docs, there is no 'delete' counterpart to
> 'collection.build' for association members.
>
> Thanks for any comment,
>
> Lille

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment