ruby-on-rails Blazer提高了ActiveRecord::ConnectionNotEstablished

3pmvbmvn  于 7个月前  发布在  Ruby
关注(0)|答案(1)|浏览(68)

我有Blazer 3.0.0运行在我的Rails 7应用程序与multi-database配置.我可以创建和保存查询然而,Blazer显示一个flash错误消息:

ActiveRecord::ConnectionNotEstablished

字符串
当我尝试运行任何查询时,如下所示。


的数据

c90pui9n

c90pui9n1#

我必须强制Blazer使用写入角色DB连接。

# /apps/decorator/blazer/base_controller_decorator.rb
# load the *_decorator.rb in the application.rb

module Blazer
  module BaseControllerDecorator
    def self.prepended(base)
      base.around_action :set_writing_role
    end

    def set_writing_role(&)
      ActiveRecord::Base.connected_to(role: :writing, &)
    end
  end
end

unless Blazer::BaseController.ancestors.include?(Blazer::BaseControllerDecorator)
  Blazer::BaseController.prepend(Blazer::BaseControllerDecorator)
end

字符串
我认为Blazer仍然使用主要的Rails应用程序数据库连接池来保存一些Blazer的Blazer相关的东西在数据库中。运行一个查询是一个GET请求,Rails将为该请求分配一个阅读角色,导致Blazer失败。

相关问题