Created
May 5, 2014 13:46
-
-
Save dhh/b0a106a00e8737280666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Profile < ActiveModel::Aggregator | |
aggregate :user | |
aggregate :email | |
def combine | |
user.save | |
user.emails.build(email_attributes).save | |
end | |
end | |
class ProfileController < ApplicationController | |
def create | |
@profile = Profile.new(profile_attributes) | |
if @profile.save | |
redirect_to somewhere | |
else | |
render :new | |
end | |
end | |
end |
why have a separate api for combine, rather than just Profile having save? it is because you don't want to override a save method it would have inherited?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aggregator could automatically expose its aggregates as prefixed attributes: