This project is archived and is in readonly mode.
Make Rails::Generators::Migration#next_migration_number method a class method, so it possible to use it in custom generators
-
Repository
(from [17bee0dd2fcce2d040bd6edda3e19cb11c5813d9]) Change Rails::Generators::Migration protected instance methods to class methods. [#3820 Make Rails::Generators::Migration#next_migration_number method a class method... status:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/17bee0dd2fcce2d040bd6edda3e19c... -
José Valim
- State changed from new to resolved
-
Steve
It looks like the changes in #next_migration_number for this were reverted in an immediately following commit on the same day(101a8fa5f8cbf0f981ca984a279fb9838c79a751). Was that intended?
-
kmandrup
Please do the fix again :)
I have been banging my head against this issue all morning, until I found this ticket!
Hope it will be fixed in the next Rails (beta4?) release -
Lailson Bandeira
Why the fix was reverted? Any problem with it?
-
David Jones
- Importance changed from to Low
When running my own generator that tries to use the migration_template method I get:
/Users/djones/.rvm/gems/ruby-1.8.7-p299/gems/railties-3.0.0.rc/lib/rails/generators/migration.rb:30:in
next_migration_number': NotImplementedError (NotImplementedError)Can someone change this ticket to open?
-
Oleg
Wait. Why is this resolved?
/Library/Ruby/Gems/1.8/gems/railties-3.0.0/lib/rails/generators/migration.rb:30:in
next_migration_number': NotImplementedError (NotImplementedError) -
José Valim
It is a class method, but it is implemented by child classes (like AR::Generators::Base) and not Rails::Generators::Migration.
-
Oleg
I guess the root question is what's the proper way to create generator with a migration? This is what I have:
class GemGenerator < Rails::Generators::Base include Rails::Generators::Migration def generate_migration migration_template 'gem_migration.rb', 'db/migrate/gem_migration.rb' end endThis blows up with the "next_migration_number: NotImplementedError" error. It's hard to piece together what's the proper way to go about it. I'm sure I'm not the only one.
-
José Valim
If you are writing a migration for active record, you need to add this to your generator:
def self.next_migration_number
ActiveRecord::Generators::Base.next_migration_numberend
Try checking Rails::Generators::Migration source code, it may help.
-
Oleg
I got it running, but with extra require and include it basically became this:
def self.next_migration_number(dirname) orm = Rails.configuration.generators.options[:rails][:orm] require "rails/generators/#{orm}" "#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname) endWorks now, but I still don't understand why it has to be like this.
-
José Valim
Your migration template only supports Active Record, so why do you want to make it ORM agnostic? This is exactly why Rails should not have the code above. Because people would assume a migration template would work for all ORMs and it definitely won't.
Just require 'rails/generators/active_record' at the top of the file and reference ActiveRecord::Generators::Base directly as I showed previously.
-
Oleg
I'm not really familiar with other orms besides AR, but I see what you're saying. It works. Thanks for your help.
