Skip to content

Instantly share code, notes, and snippets.

@davedash
Last active August 28, 2015 17:54
Show Gist options
  • Save davedash/bc3fe7245801e3b4ce0a to your computer and use it in GitHub Desktop.
Save davedash/bc3fe7245801e3b4ce0a to your computer and use it in GitHub Desktop.
No timing
# Import a blog post.
def ingest(external_post)
map = AuthorExternalMap.find_by_external_id(external_post.author_id)
if map.present?
author = Author.where(id: map.author_id).include(posts: [:categories]).try(:first)
category = Category.find_or_create_by!(name: external_post.category_name)
post = find_existing_post(external_post)
if post.present?
post.authors << author
post.category = category
else
post = author.post.create!(name: external_post.name, category: category, content: external_post.content)
author.touch
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment