Skip to content

Instantly share code, notes, and snippets.

@darron
Created January 7, 2010 18:46
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 darron/271448 to your computer and use it in GitHub Desktop.
Save darron/271448 to your computer and use it in GitHub Desktop.
class Link < ActiveRecord::Base
has_and_belongs_to_many :bundle
validates_presence_of :url
before_save :grab_title
require 'hpricot'
require 'open-uri'
# TODO: There's no error checking at all.
def grab_title
doc = Hpricot(open("#{url}"))
title = doc.search("title").inner_html
@link.title = title unless blank?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment