Invalid nested resource added to collection before save in Rails 4 -
this routes.rb
resources :posts resources :comments end
and post/show.html.haml
.post %h1= @post.title %p= @post.content - @post.comments.each |comment| .comment %h3= comment.name %p= comment.text = form_for([@post, @post.comments.build]) |f| = f.label :name = f.text_field :name = f.label :text = f.text_area :text = f.submit
the problem when try save invalid comment still gets added @post.comments , printed out. if refresh invalid comment disappears, still want avoid if possible - , wondering best practice is?
currently i'm working around issue doing check:
- unless comment.invalid?
any appreciated! :-)
if wants know, solved problem in following way:
= form_for([@post, @comment = @comment || @post.comments.build)
Comments
Post a Comment