Commit f5d800b5 by jyurek

Added generator

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@212 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent cfdaea60
Usage:
script/generate attachment Class attachment1 attachment2
This will create a migration that will add the proper columns to your class's table.
\ No newline at end of file
class PaperclipGenerator < Rails::Generator::NamedBase
attr_accessor :attachments
def initialize(*args)
super(*args)
@attachments = args
end
def manifest
record do |m|
m.migration_template "paperclip_migration.rb", File.join('db', 'migrate')
end
end
end
\ No newline at end of file
class AddPaperclipAttachmentColumnsTo<%= class_name.underscore.camelize %> < ActiveRecord::Migration
def self.up
<% attachments.each do |attachment| -%>
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
<% end -%>
end
def self.down
<% attachments.each do |attachment| -%>
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
<% end -%>
end
end
......@@ -29,6 +29,11 @@ namespace :paperclip do
puts " Done."
end
desc "Generates a migration to add attachments to a class."
task :migration do
end
# desc "Cleans out unused attachments for the given CLASS (and optional ATTACHMENT)"
# task :clean do
# klass = obtain_class
......
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