Complete the code to define a form object class inheriting from ActiveModel::Model.
class UserForm include [1] attr_accessor :name, :email end
The form object pattern uses ActiveModel::Model to get model-like behavior without database persistence.
Complete the code to add a validation for presence of :email in the form object.
class UserForm include ActiveModel::Model attr_accessor :name, :email validates :email, [1]: true end
Use validates :email, presence: true to ensure the email is not blank.
Fix the error in the save method to return false if the form is invalid.
def save return false unless [1] # persist data here true end
The valid? method runs validations and returns true or false.
Fill both blanks to define an initialize method that sets attributes from params hash.
def initialize(params = {}) params.each do |key, value| [1].send("[2]=", value) end end
Use self.send("key=", value) to assign each attribute dynamically.
Fill all three blanks to define a save method that validates, creates a User, and returns true if successful.
def save return false unless [1] user = User.new(name: [2], email: [3]) user.save end
The save method first checks validity, then creates a User with form attributes, and saves it.