gem(无意中)如何改变迁移路径?
How can a gem (unintentionally) change the migrations path?
我写了一个 Gem (https://github.com/absolutedevops/civo),这是一个简单的 Rails 引擎,包含一些 API 访问模型。
但是,当我将它包含在 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
在 https://github.com/absolutedevops/civo-ruby (which I think is the one you meant to link to), you define ENGINE_ROOT
to point to the location where your engine code is installed. Rails also uses this constant 的几个地方查看 civo-ruby 存储库,我怀疑这是发生冲突的地方。
您可以重命名常量,例如到 CIVO_ENGINE_ROOT
,或者您可以将它移动到 Civo
模块中,这样它就被命名空间了。
我写了一个 Gem (https://github.com/absolutedevops/civo),这是一个简单的 Rails 引擎,包含一些 API 访问模型。
但是,当我将它包含在 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
在 https://github.com/absolutedevops/civo-ruby (which I think is the one you meant to link to), you define ENGINE_ROOT
to point to the location where your engine code is installed. Rails also uses this constant 的几个地方查看 civo-ruby 存储库,我怀疑这是发生冲突的地方。
您可以重命名常量,例如到 CIVO_ENGINE_ROOT
,或者您可以将它移动到 Civo
模块中,这样它就被命名空间了。