[英]How can a gem (unintentionally) change the migrations path?
我写了一个Gem( https://github.com/absolutedevops/civo ),它是一个简单的Rails Engine,其中包含一些API访问模型。
但是,当我将其包含在Rails项目中时,任何生成器都会在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
查看https://github.com/absolutedevops/civo-ruby上的civo-ruby存储库(我认为这是您要链接的存储库),您定义ENGINE_ROOT
指向引擎代码的安装位置。 Rails在少数地方也使用此常数 ,我怀疑这是发生碰撞的地方。
您可以重命名常量,例如,将其重命名为CIVO_ENGINE_ROOT
,也可以将其移动到Civo
模块中,以便对其命名空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.