问题描述
我有一个生成器,负责创建少量迁移文件。 我使用migration_template创建了一个具有版本号的正确迁移文件。
require "rails/generators"
class MyMigrationGenerator < Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path("templates/migrations",__dir__)
# add_reference_migration.rb.erb is a migration template
# which is placed in templates/migrations/add_reference_migration.rb.erb
def process
migration_template(
"add_reference_migration.rb.erb","db/migrate/my_migration_file_name.rb",migration_version: migration_version
)
end
def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end
def migration_version
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MInor}]"
end
end
我遇到一个错误:
NoMethodError: undefined method `last' for nil:NilClass from ~/.rvm/gems/ruby-2.6.6@project/gems/thor-0.20.3/lib/thor/actions.rb:101:in `destination_root'
搜索了一段时间后,我知道可以设置self.destination_root=<path-where-migration-file-will-be-saved>
了,但这在migration_template
的上下文中没有记录。
即使我设置了它,也会导致其他一些问题。
在Ruby on Rails中使用migration_template
的正确方法是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)