Last active
August 28, 2015 17:54
-
-
Save davedash/bc3fe7245801e3b4ce0a to your computer and use it in GitHub Desktop.
No timing
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
# 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