Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Last active December 18, 2015 06:09
Show Gist options
  • Save freshtonic/5737671 to your computer and use it in GitHub Desktop.
Save freshtonic/5737671 to your computer and use it in GitHub Desktop.
def self.create_or_update_from_extraction_result(user, extraction_result, bookmarklet_params)
ActiveRecord::Base.transaction do
article = Article.for_source_url(bookmarklet_params['source_url']) || Article.new
if extraction_result.success?
article.body = extraction_result.content
else
article.body = ""
end
article.title = extraction_result.title || "[missing title]"
article.source_url = bookmarklet_params['source_url']
article.successful_extraction = extraction_result.success?
article.save!
bookmark = Bookmark.for_user_and_article(user, article) || Bookmark.new
bookmark.user = user
bookmark.article = article
bookmark.title = bookmarklet_params['title'] || extraction_result.title || "[missing title]"
bookmark.source_url = bookmarklet_params['source_url']
bookmark.save!
bookmark
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment