Commit 500f1bb1 by Daniel Schierbeck

Add a helper that creates the Paperclip columns

    This can be used in migrations, i.e.

      create_table :users do |t|
        t.has_attached_file :avatar
      end

(three commits squashed into one by Alexey Mahotkin <squadette@gmail.com>)
parent 5f3b88d1
......@@ -80,17 +80,13 @@ In your migrations:
class AddAvatarColumnsToUser < ActiveRecord::Migration
def self.up
add_column :users, :avatar_file_name, :string
add_column :users, :avatar_content_type, :string
add_column :users, :avatar_file_size, :integer
add_column :users, :avatar_updated_at, :datetime
change_table :users do |t|
t.has_attached_file :avatar
end
end
def self.down
remove_column :users, :avatar_file_name
remove_column :users, :avatar_content_type
remove_column :users, :avatar_file_size
remove_column :users, :avatar_updated_at
drop_attached_file :users, :avatar
end
end
......
require 'paperclip'
require 'paperclip/schema'
module Paperclip
if defined? Rails::Railtie
......@@ -21,6 +22,9 @@ module Paperclip
File.send(:include, Paperclip::Upfile)
Paperclip.options[:logger] = defined?(ActiveRecord) ? ActiveRecord::Base.logger : Rails.logger
ActiveRecord::ConnectionAdapters::Table.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Paperclip::Schema)
end
end
end
module Paperclip
module Schema
def has_attached_file(name)
column :"#{name}_file_name", :string
column :"#{name}_content_type", :string
column :"#{name}_file_size", :integer
column :"#{name}_updated_at", :datetime
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment