We’ve talked before about form objects and how they can simplify our Rails views. Now I’d like to present a more complex scenario and one way to tackle it.

We have two associated models:

# app/models/user.rb

class User < ApplicationRecord

has_one :location

end



# app/models/location.rb

class Location < ApplicationRecord

belongs_to :user

end

We want to create one instance of each model using a single registration form.