Rails RSpec with Multiple Databases

后端 未结 4 911
情书的邮戳
情书的邮戳 2021-01-28 00:05

I run a Rails app, and we\'re in the process of splitting out our signup process to a separate app. The signup app has its own separate database (for CMS and collecting prospect

4条回答
  •  [愿得一人]
    2021-01-28 00:54

    We just used interpolation for this:

    class ServiceModel < ActiveRecord::Base
      establish_connection :"main_app_#{Rails.env}"
    end
    

    The funny :"main_app_" syntax makes a symbol from a string. This could be also written "main_app_#{Rails.env}".to_sym. In either case with Rails 4.1 this must be a symbol (under 3.2 we had just used a string).

提交回复
热议问题