Validating collections

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs