Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

generate for rails3

  • Loading branch information...
commit f50add6c88314f180c8d8ace900e60482d2ff979 1 parent 3b5ff6c
@jinzhu jinzhu authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.