【问题标题】:How do you mount a :mountable Rails Engine in a :full Engine and run migrations?如何在 :full 引擎中安装 :mountable Rails 引擎并运行迁移?
【发布时间】:2013-10-09 16:29:32
【问题描述】:

我有一个可挂载的 Rails 引擎,它有自己的模型和命名空间表 (MountableEngine)。我有另一个引擎,--full 一个,它有自己的架构 (FullEngine)。我希望将这两个引擎都包含到实际应用中,但只包含完整的引擎,即应用的 GemFile 中的 FullEngine

这可能吗?我还没有尝试在骨架 Rails 应用程序中对此进行测试,但在 FullEngine 中,我已将可挂载引擎包含在其 Gemfile 中,如下所示:

gem 'mountable_engine', path: "../my/path/mountable_engine"

但是在FullEngine 中运行迁移,我得到了这个错误:

rake mountable_engine:install:migrations
Don't know how to build task 'mountable_engine:install:migrations'

我希望迁移在FullEngine 中运行的原因是我希望FullEngine 封装两个引擎的组合逻辑和功能,以便实际应用程序通过仅包含FullEngine 来继承它们

【问题讨论】:

    标签: ruby-on-rails ruby migration


    【解决方案1】:

    我按照此处 Pivotal Lab 的博客 leave your migrations in your Rails engines 上的说明进行操作,该博客建议您对 Rails::Engine 类进行猴子修补,以将引擎的迁移paths附加到调用应用程序的迁移路径设置中:

    initializer :append_migrations do |app|
      unless app.root.to_s.match root.to_s
        app.config.paths["db/migrate"] += config.paths["db/migrate"].expanded
      end
    end
    

    所以我不确定我的问题的答案是否是:“是的,以这种方式构建引擎是个好主意”......但是这个猴子补丁至少允许所有迁移从你的依赖运行引擎。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多