Created
September 20, 2019 10:33
-
-
Save vfonic/aa8502f163d136411c6b0197e130c1ba to your computer and use it in GitHub Desktop.
This file contains 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
def save | |
ActiveRecord::Base.transaction do | |
user = User.save(username: username) # user doesn't have to be instance var @user | |
add_errors(user.errors) unless user.persisted? | |
tweet = Tweet.save(body: first_tweet, user_id: user.id) | |
add_errors(tweet.errors) unless tweet.persisted? | |
user.persisted? && tweet.persisted? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment