宝石(无意中)如何改变迁移路径?

时间:2016-04-11 10:46:14

标签: ruby-on-rails ruby rubygems

我写了一个Gem(https://github.com/absolutedevops/civo),它是一个包含一些API访问模型的简单Rails引擎。

但是,当我将它包含在Rails项目中时,任何生成器都会在Gem的源代码下创建文件而不是项目。我无法看到我在Gem中所做的任何会导致这种情况的事情。它是可重复的(它发生在我公司的两个项目中,我可以通过下面的一系列步骤重现它。)

有谁能告诉我我是如何管理的?多年来我一直是Rails用户,但之前从未遇到过这种情况。

$ rails -v
Rails 4.2.6
$ rails new civo-test
[...]
Bundle complete! 12 Gemfile dependencies, 55 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
         run  bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted
$ cd civo-test
$ echo 'gem "civo"' >> Gemfile
$ bundle
[...]
Bundle complete! 13 Gemfile dependencies, 66 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ rails g migration a_new_migration_here
Running via Spring preloader in process 75091
      invoke  active_record
      create    db/migrate/20160411093346_a_new_migration_here.rb
$ ls -l db/migrate/20160411093346_a_new_migration_here.rb
ls: db/migrate/20160411093346_a_new_migration_here.rb: No such file or directory
$ rails g migration a_new_migration_here                 
Running via Spring preloader in process 75193
      invoke  active_record
   identical    db/migrate/20160411093346_a_new_migration_here.rb
$ ls -l /Users/andy/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/civo-0.3.21/db/migrate/ 
total 8
-rw-r--r--  1 andy  staff  73 11 Apr 10:33 20160411093346_a_new_migration_here.rb

1 个答案:

答案 0 :(得分:2)

查看https://github.com/absolutedevops/civo-ruby处的civo-ruby存储库(我认为是您要链接到的存储库),您可以定义ENGINE_ROOT以指向安装引擎代码的位置。在很少的地方,Rails也uses this constant,我怀疑这是发生碰撞的地方。

您可以重命名常量,例如至CIVO_ENGINE_ROOT,或者您可以将其移至Civo模块,以便将其命名为。

相关问题