Commit c334c989 by Jon Yurek

All generators working with Rails 2 and 3. Tested in app for Rails 2 and 3.

parent f2ef8c40
class PaperclipGenerator < Rails::Generators::Base
include Rails::Generators::Migration
require 'rails/generators/active_record'
class PaperclipGenerator < ActiveRecord::Generators::Base
desc "Create a migration to add paperclip-specific fields to your model."
argument :attachment_class, :required => true, :type => :string, :desc => "The class to migrate.",
:banner => "ClassName"
argument :attachment_names, :required => true, :type => :array, :desc => "The names of the attachment(s) to add.",
:banner => "attachment_one attachment_two attachment_three ..."
......@@ -19,7 +17,7 @@ class PaperclipGenerator < Rails::Generators::Base
protected
def migration_name
"add_attachment_#{attachment_names.join("_")}_to_#{attachment_class.underscore}"
"add_attachment_#{attachment_names.join("_")}_to_#{name.underscore}"
end
def migration_file_name
......@@ -30,8 +28,4 @@ class PaperclipGenerator < Rails::Generators::Base
migration_name.camelize
end
def self.next_migration_number(dirname) #:nodoc:
Time.now.strftime("%Y%m%d%H%M%S")
end
end
class <%= migration_class_name %> < ActiveRecord::Migration
def self.up
<% attachment_names.each do |attachment| -%>
add_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
add_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
add_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
add_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
add_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
<% end -%>
end
def self.down
<% attachment_names.each do |attachment| -%>
remove_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_file_name
remove_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_content_type
remove_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_file_size
remove_column :<%= attachment_class.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_file_size
remove_column :<%= name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
<% end -%>
end
end
......@@ -4,7 +4,7 @@ module Paperclip
if defined? Rails::Railtie
require 'rails'
class Railtie < Rails::Railtie
config.after_initialize do
initializer "paperclip.insert_into_active_record" do
Paperclip::Railtie.insert
end
rake_tasks do
......
puts "THIS IS THE RAILS/INIT.RB FILE"
require 'paperclip/railtie'
Paperclip::Railtie.insert
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