Skip to content

Instantly share code, notes, and snippets.

@arunthampi
Created September 23, 2011 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunthampi/1236434 to your computer and use it in GitHub Desktop.
Save arunthampi/1236434 to your computer and use it in GitHub Desktop.
Transactions for nested creation of objects in a controller
Channel.transaction do
@channel.save
rss_bot = @channel.build_youtube_rss_bot(:username => youtube_username)
if rss_bot.valid?
rss_bot.save
Delayed::Job.enqueue(SocialFeed::YoutubeRssScraper.new(rss_bot))
else
@channel.errors.add(:youtube_username, rss_bot.errors[:username])
raise ActiveRecord::Rollback
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment