代码之家  ›  专栏  ›  技术社区  ›  Emu

Rails将记录从暂存复制到生产

  •  0
  • Emu  · 技术社区  · 5 年前

    我在做一个有两个环境的项目 登台 . 营销团队在登台环境中创建记录,等待客户批准。如果客户同意,那么他们必须在生产环境中创建相同的记录,这是一种重新工作。

    我想把暂存记录移到生产中去。为此,我在 models/ad_to_production.rb ,在那里我建立了与生产数据库的连接。原始型号名称为 Ad .

    问题是 ad

    class Ad < ActiveRecord::Base
    #  id              :integer          not null, primary key
    #  title           :string
    #  image           :string
    #  destination_url :text
    #  created_at      :datetime         not null
    #  updated_at      :datetime         not null
    end
    
    
    class AdToProduction < ActiveRecord::Base
      establish_connection :"production_db"
    
    
    
      def copy(staging_ad)
        self.title = staging_ad.title
        self.image = image if staging_ad.image.present?
        # skip codes
      end 
    end
    

    如有任何建议,我们将不胜感激!

    0 回复  |  直到 5 年前
        1
  •  0
  •   Daniel    5 年前