【问题标题】:How to avoid rake assets:precompile to load the entire application on rails 4.2.11?如何避免 rake assets:precompile 以在 rails 4.2.11 上加载整个应用程序?
【发布时间】:2019-09-18 10:28:00
【问题描述】:

我有一个动态路由文件,它使用数据库定义约束。

XXX::Engine.routes.draw do
  scope '(:locale)', locale: /#{I18n.available_locales.join('|')}/ do
    get "/:intent-:currency", to: 'offers#index', constraints: { intent: /deposit|withdraw/, currency: load_from_database }
  end
end

我必须从数据库加载约束,因为表达式比这更复杂。我简化了我的观点。

rake assets:precompile 加载整个应用程序,但我的 CI 上还没有数据库。如果我尝试运行rake db:create && rake db:migrate,它仍然会尝试加载应用程序让我卡住,因为我需要动态路由的数据库,但我无法在加载应用程序时迁移数据库

我需要找到一种方法来避免rake assets:precompile 不加载整个应用程序,或者至少在它进行预编译时避免数据库连接

NullDb 适配器似乎正在工作,但应该有另一种方法,因为我不想在我的项目中添加更多的宝石

我应该能够在不加载应用程序的情况下运行rake assets:precompile(routes.rb 文件已加载,它取决于数据库,因此它将失败,因为在我之前需要预编译的管道上)

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 rake


    【解决方案1】:

    NullDb gem 看起来很诱人,但我更愿意避免将 gem 添加到我的项目中

    这对我有用。拉了一天头发后回答我自己的问题

    XXX::Engine.routes.draw do
      scope '(:locale)', locale: /#{I18n.available_locales.join('|')}/ do
        get "/:intent-:currency", to: 'offers#index', constraints: { intent: /deposit|withdraw/, currency: load_from_database } unless defined?(::Rake::SprocketsTask)
      end
    end
    

    【讨论】:

    猜你喜欢
    • 2011-07-25
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 2013-09-09
    • 2012-12-08
    相关资源
    最近更新 更多