Using rails 3.2.2, btw.
1.9.3-p125 :005 > a = Article.first
=> #<Article id: 1, title: "Sample Article Title", body: "This is the text for my article, woo hoo!", created_at: "2012-04-13 00:16:04", updated_at: "2012-04-13 00:16:04">
1.9.3-p125 :006 > a.comments
=> [four comments]
1.9.3-p125 :007 > c = a.comments.new
=> #<Comment id: nil, article_id: 1, author_name: nil, body: nil, created_at: nil, updated_at: nil>
1.9.3-p125 :008 > a.comments
=> [four comments, #<Comment id: nil, article_id: 1, author_name: nil, body: nil, created_at: nil, updated_at: nil>]
This becomes a problem when you want to do something like this:
def show
@article = Article.find(params[:id])
@comment = @article.comments.new
endand in the view
<%= render :partial => 'comment', :collection => @article.comments %>
<h3>Post a Comment</h3>
<%= form_for @comment do |f| %>
...Because you have to make the comment for the form, but then it tries to render it in the collection.
Is this new? Have I just never noticed it?
That always happened unfortunately. try something like
:collection => @article.comments.reject(&:new_record?)