-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Labels
Description
Hi @andypike,
First off: thanks a lot for your work on Rectify!
So I've been rectifying a rather big, complex form and been running into some questions.
One of those is: how do you display errors on nested forms?
Take for instance the blog example again:
class Blog < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :blog
end
class BlogForm < Rectify::Form
attribute :title, String
attribute :posts, Array[PostForm]
end
class PostForm < Rectify::Form
attribute :title, String
attribute :body, String
endNow in the view, we want to show validation errors. Typically, this is something like this:
-# app/views/blogs/_form.html.haml
- if form.errors.any?
.alert
%h4
= pluralize(form.errors.count, 'error')
prohibited this blog from being saved:
%ul
- form.errors.each do |key, message|
%li= "#{key} #{message}"Now if we have a validation error on a PostForm, this error will not be displayed, since it's in e.g. form.post.first.errors.
It's not difficult to loop over all the errors of nested models, but if you have many nested forms this becomes tedious.
Do you think it would be nice to be able to do something like form.all_errors?
FraDim