如何避免rake资产:预编译以在rails 4.2.11上加载整个应用程序?

问题描述 投票:1回答:1

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

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个回答
0
投票

NullDb 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
© www.soinside.com 2019 - 2024. All rights reserved.