Musings from my development journey.Topics
Talk given by Andrew Markle.
An object that can be passed into a form.
Typically added to a new directory called
Working with Nested Attributes, managing data between sessions, and implementing validations from multiple models.
Sample form object, written from scratch:
class CompanyForm include ActiveModel::Model attr_accessor :name, :email, :etc def company @company ||= Company.new(name: name) end # Validations # Virtual attributes # Delegates end
Alternate: Reform Gem
class AlbumForm < Reform::Form property :title validates :title, presence: true property :artist do property :full_name validates :full_name, presence: true end collection :songs do property :name end end
The Reform gem includes the concept of prepopulators and populators, the easiest way to understand it is: