Rails 3 plugin - Generate a custom migration file

Posted by moshimoshi on Stack Overflow See other posts from Stack Overflow or by moshimoshi
Published on 2010-05-29T22:26:31Z Indexed on 2010/05/29 22:32 UTC
Read the original article Hit count: 497

Hi,

On this article http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/ we can see the following codes which allow to invoke a migration file:

class ActsAsTaggableOnMigrationGenerator < Rails::Generators::Base
  invoke "migration", %(add_fields_to_tags name:string label:string)
end

The command looks like:

$ rails generate acts_as_taggable_on User
  invoke  migration
  invoke    active_record
  create      db/migrate/20100529220831_user.rb
   error  "add_fields_to_tags name:string label:string" [not found]

I don't understand why I get this error... and I have 2 questions about:

1/ How can I do to customize the name of the generated file? Just like: 20100529220831_add_tag_field_to_users.rb.

2/ How can I pass in some args such as:

$ rails generate acts_as_taggable_on User tag1 tag2 tag2

in order to customize the generating file such as tag1:string tag2:string tag3:string...

Many thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-plugins