Commit e0a67324 by Daniel Schierbeck

Refactor the implementation of the schema helpers

parent ffbfc24e
module Paperclip module Paperclip
module Schema module Schema
def has_attached_file(name) @@columns = {:file_name => :string,
column :"#{name}_file_name", :string :content_type => :string,
column :"#{name}_content_type", :string :file_size => :integer,
column :"#{name}_file_size", :integer :updated_at => :datetime}
column :"#{name}_updated_at", :datetime
def has_attached_file(attachment_name)
@@columns.each do |name, type|
column_name = full_column_name(attachment_name, name)
column(column_name, type)
end
end
def drop_attached_file(table_name, attachment_name)
@@columns.each do |name, type|
column_name = full_column_name(attachment_name, name)
remove_column(table_name, column_name)
end
end end
def drop_attached_file(table_name, name) protected
remove_column table_name, :"#{name}_file_name"
remove_column table_name, :"#{name}_content_type" def full_column_name(attachment_name, column_name)
remove_column table_name, :"#{name}_file_size" "#{attachment_name}_#{column_name}".to_sym
remove_column table_name, :"#{name}_updated_at"
end end
end 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