Skip to content

Instantly share code, notes, and snippets.

@grobie
Created October 25, 2008 15:20
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 grobie/19750 to your computer and use it in GitHub Desktop.
Save grobie/19750 to your computer and use it in GitHub Desktop.
class Doc < File
has_attachment :content_type => 'application/msword',
:max_size => 2.megabytes,
:storage => :file_system
end
class File < ActiveRecord::Base
belongs_to :invoice
end
class Invoice < ActiveRecord::Base
has_one :pdf
has_one :doc
end
class InvoicesController
def new
@invoice = Invoice.new
@file = File.new
end
end
class Pdf < File
has_attachment :content_type => 'application/pdf',
:max_size => 2.megabytes,
:storage => :file_system
end
class CreateFiles < ActiveRecord::Migration
def self.up
create_table :files do |t|
t.string :type, :file_name, :content_type
t.integer :size, :invoice_id
t.timestamps
end
end
def self.down
drop_table :addresses
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment