How do people write their Rails migrations that involve Paperclip? I feel that I might be missing something obvious as I have now written my own migration helpers hacks that mak
There are generators included in the gem for this:
Rails 2:
script/generate paperclip Class attachment1 (attachment2 ...)
Rails 3:
rails generate paperclip Class attachment1 (attachment2 ...)
e.g.
rails generate paperclip User avatar
generates:
class AddAttachmentsAvatarToUser < 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
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
end
end
Also see the helper methods used in the example in the readme
class AddAvatarColumnsToUser < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.has_attached_file :avatar
end
end
def self.down
drop_attached_file :users, :avatar
end
end