6

I am using following gem for editor.

gem "wysihat-engine", "~> 0.1.13"

When I run 'rails generate wysihat' it's generate all image file, but can't generate migration and giving following error

c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/generators/migration.rb:30:in `next_migration_number': NotImplementedError (NotImplementedError)
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/generators/migration.rb:49:in `migration_template'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/wysihat-engine-0.1.13/lib/generators/wysihat_generator.rb:60:in `install_wysihat'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/generators.rb:170:in `invoke'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/generate.rb:12:in `<top (required)>'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:29:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Thanks for any help!

vajapravin
  • 1,363
  • 3
  • 16
  • 29
  • See https://github.com/rails/rails/blob/7ebfb319ffbfc1f9d3dc5439052ae06019bf4290/railties/lib/rails/generators/migration.rb#L30 and comment below for solution. – mattes Feb 05 '20 at 20:04

3 Answers3

8

I just ran in to this issue with Rails 4.1.5

I fixed it by implementing in my migration like this:

class MigrationGenerator < ::Rails::Generators::Base
  include Rails::Generators::Migration

  private
  def self.next_migration_number(dirname)
    next_migration_number = current_migration_number(dirname) + 1
    ActiveRecord::Migration.next_migration_number(next_migration_number)
  end
end
mattes
  • 8,936
  • 5
  • 48
  • 73
beno1604
  • 891
  • 9
  • 9
  • [Rails::Generators::Migration](https://api.rubyonrails.org/v6.0/) assumes that you implement the next migration version method. An implementation can be found here: https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/rails/generators/active_record/migration.rb#L12-L16 – mattes Feb 05 '20 at 19:59
0

use include ActiveRecord::Generators::Base instead. (update to the latest version of your gem probably works).

Pierre Valade
  • 3,388
  • 3
  • 24
  • 29
0
require 'rails/generators/active_record'
class YourGenerator < ActiveRecord::Generators::Base
  # save you from `next_migration_number': NotImplementedError and undefined method `migration_template'
end
Sergey Sokolov
  • 994
  • 7
  • 6
  • Inheriting from `ActiveRecord::Generators::Base` won't allow `rails generate` command to find my generator. – mattes Feb 05 '20 at 19:46