If you have a conventional migration, you can invoke the migration
generator explicitly:

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

However, if you need a customized template, currently you have to copy
the logic that gets the migration number. Maybe we could expose that
as a class method, so you just need to do:

  ActiveRecord::Generators::Base.next_migration_number

Feel free to work in a patch and assign to me when it's done. If not
in mood for a patch, please create a ticket on Lighthouse and assign
to me, so I can tackle it later.

On Jan 30, 1:46 pm, szimek <szi...@gmail.com> wrote:
> Thanks, but the problem is that if I add the following line to my
> generator:
>
> hook_for :orm, :as => "migration"
>
> it invokes i.e. ActiveRecord::Generators::Migration and it says that
> the name attribute is missing, probably because AR::G::Migration
> inherits from AR::G::Base, which inherits from
> Rails::Generators::NamedBase. I don't want to specify migration name,
> as it's already hardcoded in my generator, I just want to add a proper
> prefix (i.e. timestamp), which is added by the "next_migration_number"
> method.
>
> All I need for my generator is to be able to access
> "migration_template" method and "next_migration_number" depending on
> ORM selected. It works fine if I simply copy "next_migration_number"
> method from ActiveRecord::Generators::Base, but I doubt it's the
> proper way to do it :)
>
> Here's how it looks currently:http://gist.github.com/290534.
>
> BTW. Are there Rails 3 API docs available anywhere? I can't generate
> my own, because I got the following error: "wrong constant name ./DOC/
> TEMPLATE/HORO"
>
> On Jan 30, 12:11 am, Kristian <kmand...@gmail.com> wrote:
>
>
>
> > If you look at the scaffold generator, it is able to apply the correct
> > model/migration generator depending on the orm setting in
> > application.rb.
> > This is handled transparently as I see it. It simply calls the correct
> > migration and model generators with a name corresponding to the orm
> > setting.
> > Check out myhttp://github.com/kristianmandrup/mongo_model_r3foran
> > example. This can be used 
> > byhttp://github.com/kristianmandrup/very_nifty_generators
> > Which contains a scaffold generator. This calls the mongo_mapper
> > generator if orm is set to :mongo_mapper and so on...
> > Something similar should be possible with migrations.
>
> > Also see:http://guides.rails.info/generators.htmlformore details ;)
>
> > Good luck!
>
> > Kristian
>
> > On Jan 29, 9:54 pm, szimek <szi...@gmail.com> wrote:
>
> > > Hi,
>
> > > I'd like to add Rails 3 compatible generator to acts_as_taggable_on
> > > gem (all it does is call "migration_template" method) and got a
> > > problem with "next_migration_number" method not being implemented.
>
> > > For ActiveRecord this method is defined in
> > > ActiveRecord::Generators::Base class, which inherits from NamedBase
> > > class. How can I use it inside my generator, which inherits from
> > > Rails::Generators::Base? How to use "hook_for :orm" here, so that the
> > > proper "next_migration_number" method definition is be used?
>
> > > Cheers,
> > > Szymek

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to