Created
          March 25, 2010 16:20 
        
      - 
      
- 
        Save justincaldwell/343750 to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | require 'mime/types' | |
| require 'RMagick' | |
| class Photo < ActiveRecord::Base | |
| establish_connection 'portal' | |
| set_table_name 'photos' | |
| belongs_to :kase | |
| belongs_to :doctor | |
| belongs_to :photo_email | |
| has_attached_file :photo, | |
| :styles => { | |
| :thumb => ["150x150>", :jpg], | |
| :medium => ["600x600>", :jpg], | |
| :Case => ["1200x1200>", :jpg] }, | |
| :processors => [:rotater, :thumbnail], | |
| :default_style => :medium, | |
| :path => ':rails_root/public/kase_photos/:style/:kase_id/:id_:basename.:extension', | |
| :url => '/kase_photos/:style/:kase_id/:id_:basename.:extension' | |
| after_photo_post_process :post_process_photo | |
| named_scope :unattached, :conditions => "RTRIM(kase_id) = '' ", | |
| :order => 'created_at ASC' | |
| # ... | |
| # More named scopes here | |
| # ... | |
| # Fix the mime types. Needs mime-types gem | |
| def swfupload_file=(data) | |
| data.content_type = MIME::Types.type_for(data.original_filename) | |
| self.photo = data | |
| end | |
| @@exif_date_format = '%Y:%m:%d %H:%M:%S' | |
| # Post processing | |
| def post_process_photo | |
| #... | |
| #... | |
| end | |
| # Save photos and returns nil if all the photo didn't save | |
| # Otherwise return the number of photos saves | |
| def self.save_from_email photos, pemail | |
| photocount = 1 | |
| photos.each do |p| | |
| photo = Photo.new(:photo => File.new(p), :source => 'email', | |
| :photo_email_id => pemail.id, :kase_id => pemail.kase_id, | |
| :doctor_id => pemail.doctor_id) | |
| photo.save! ? photocount += 1 : break | |
| end | |
| photocount == photos.length ? photocount : nil | |
| end | |
| # Experimental for the time being | |
| def self.generate_pdf | |
| #.. | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment