As posted in the comments the fill flag (^) does exactly what Mark needs. That flag is used to resize the image based on the smallest fitting dimension. That is, the image is resized to completely fill (and even overflow) the pixel area given. The code should be changed to this:
has_attached_file :attachment, :styles => { :medium => ['640x480^', :jpg] }
Documentation about this flag can be found here: http://www.imagemagick.org/Usage/resize/#fill.