Displaying 5 results from an estimated 5 matches for "all_valid".
2006 Apr 14
2
spot the error (I can''t, I''m new)
I have a form that I want to use to update multiple
objects. In the controller,
@grades = Grade.find(params[:grade].keys)
@grades.each_with_index do |grade, i|
grade.update_attribute(params[:grade][i])
end
all_valid = @grades.inject(true) {|memo, c|
c.valid? && memo }
this doesn''t update the attributes as I would expect.
(I would just use
Grade.update(params[:grade].keys,params[:grade].values)
but I can''t figure out how to validate the data using
that method. Could someone please e...
2006 Feb 03
7
how to add multiple new records from one form
I''m trying to provide our customers with a page where they can add up to
20 items to their cart in one form. The form simply has 20 rows with
each row containing a text input for product code and a text input for
quantity.
I''ve tried having the controller create an array that has an object for
each row by looping through something like:
@new_items[1] = Cart.new
and the
2006 Jan 19
5
TIP: Using field_error_proc to add style attributes to form elements
I just put this up on the wiki, and thought I''d share in case it''s
useful to anyone else. This is handy if you don?t want to wrap your
input elements inside a div when an error occurs, but instead want to
add some sort of CSS style to fields with errors:
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
msg = instance.error_message
error_style =
2006 Apr 12
0
Validating collections
...ve was to use something
like
[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? }
>or
>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?...
2006 Mar 08
19
Creating multiple rows with one form
Hello. I''ve been trying this out for the past two days and I can''t seem to
get it. I''m going to have a page where you can upload x amount of images at
once. Lets say 10 images need to be uploaded, all with a caption.
I''d like to have a browse button to choose the file, then the caption. Now,
if I put 10 of them in one form, fill them all out and submit, I get