require 'net/http' require 'uri' class Post < ActiveRecord::Base before_save :pygmentize_body def pygmentize_body self.pygmentized_body = Net::HTTP.post_form(URI.parse('http://pygments.appspot.com/'), {'lang'=>language, 'code'=>body}).body end end # Then you can call @post.pygmentized_body to get the stored HTML with syntax highlighting without doing another request