Skip to content

Instantly share code, notes, and snippets.

@vfonic
Created September 20, 2019 10:33
Show Gist options
  • Save vfonic/aa8502f163d136411c6b0197e130c1ba to your computer and use it in GitHub Desktop.
Save vfonic/aa8502f163d136411c6b0197e130c1ba to your computer and use it in GitHub Desktop.
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