Skip to content

Instantly share code, notes, and snippets.

@milushov
Created December 21, 2012 14:58
Show Gist options
  • Save milushov/4353295 to your computer and use it in GitHub Desktop.
Save milushov/4353295 to your computer and use it in GitHub Desktop.
class Attachment < ActiveRecord::Base
before_create :default_name
attr_accessible :file, :attachable_id
mount_uploader :file, FileUploader
belongs_to :attachable, polymorphic: true
def default_name
self.name ||= File.basename(file.filename, '.*').titleize if file
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment