Define nested forms and collections
masterReform supports nested objects and collections. When you define a property as a nested block or a collection, Reform automatically wraps the associated models in their own form objects during initialization.
- Use
property :name do ... endforhas_onerelationships. - Use
collection :name do ... endforhas_manyrelationships. - You can reuse existing forms using the
form: FormClassoption.
class AlbumForm < Reform::Form
property :title
validates :title, presence: true
# Nested single object
property :artist do
property :full_name
validates :full_name, presence: true
end
# Nested collection
collection :songs do
property :name
end
# Reusing an existing form
property :artist, form: ArtistForm
end