Forum: Ruby on Rails Validating collections

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
B Gates (Guest)
on 2006-04-12 07:30
(Received via mailing list)
I saw this issue addressed in mid-January under the
heading 'TIP: Using field_error_proc to add style
attributes to form elements', but I didn't quite get

I have a collection of objects that I want to input in
one form and validate (during update).  The suggestion
in the post I referred to above was to use something
[in form]
> <% for @comment in @post.comments %>
> <%= text_field 'comment[]', 'author' %>
> <%= text_field 'comment[]', 'body' %>
> <% end %>
[in controller]
>all_valid = @post.comments.all? { |c| c.valid? }
>all_valid = @post.comments.inject(true) {|memo, c|
c.valid? && memo }
but I'm not sure how @post.comments gets filled.  I
mean, I get how to send @post to the view, but when I
return to the controller for validation, what is
@post?  And how does it relate to the data that was
passed in the form?

Brian Gates

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
This topic is locked and can not be replied to.