Permalink
Browse files

generate for rails3

  • Loading branch information...
1 parent 3b5ff6c commit f50add6c88314f180c8d8ace900e60482d2ff979 @jinzhu jinzhu committed Mar 6, 2010
Showing with 21 additions and 12 deletions.
  1. +6 −0 lib/generators/comment/USEGA
  2. +15 −12 lib/generators/comment/comment_generator.rb
View
6 lib/generators/comment/USEGA
@@ -0,0 +1,6 @@
+Description:
+ Copies comment.rb to app/models/.
+ Copies create_comment.rb to db/migrate
+
+Examples:
+ `rails generate comment`
View
27 lib/generators/comment/comment_generator.rb
@@ -1,15 +1,18 @@
-require 'rails/generators'
+require 'rails/generators/migration'
class CommentGenerator < Rails::Generators::Base
- def manifest
- record do |m|
- m.directory 'app/models'
- m.file 'comment.rb', 'app/models/comment.rb'
- m.migration_template "create_comments.rb", "db/migrate"
- end
- end
- # ick what a hack.
- def file_name
- "create_comments"
- end
+ include Rails::Generators::Migration
+
+ def self.source_root
+ @_acts_as_commentable_source_root ||= File.expand_path("../templates", __FILE__)
+ end
+
+ def self.next_migration_number(path)
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
+ end
+
+ def create_model_file
+ template "comment.rb", "app/models/comment.rb"
+ migration_template "create_comments.rb", "db/migrate/create_comments.rb"
+ end
end

0 comments on commit f50add6

Please sign in to comment.