Ruby on rails 保存其他表中的信息

Ruby on rails 保存其他表中的信息,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,大家好现在我有两张桌子: 主顾 客户 我想把所有的信息从客户列表放到客户列表中,但是我想一个字段一个字段地保存,现在我有了这个 cnx = ActiveRecord::Base.connection cnx.execute("truncate table clientesultimasgestiones") @informacion = Clientesgestion.all @informacion.each do |f| @clientesultimasgestio

大家好现在我有两张桌子:

主顾 客户

我想把所有的信息从客户列表放到客户列表中,但是我想一个字段一个字段地保存,现在我有了这个

cnx = ActiveRecord::Base.connection
cnx.execute("truncate table clientesultimasgestiones")
@informacion = Clientesgestion.all

    @informacion.each do |f|
        @clientesultimasgestion = Clientesultimasgestion.new
        @clientesultimasgestion.save(f)
        Here will be the code to save field by field from clientesgestiones table to the another one
    end
谢谢你的帮助

编辑:最后我这样做了:

    cnx.execute("truncate table clientesultimasgestiones")
    @informacion = Clientesgestion.all

    @informacion.each do |f|
        l                               = Clientesultimasgestion.new
        l.persona_id                    = f.persona_id
        l.fecha_gestion                 = f.fecha_gestion
        l.clientestipologia_id          = f.clientestipologia_id
        l.observacion                   = f.observacion
        l.user_id                       = f.user_id
        l.fecha_acuerdo                 = f.fecha_acuerdo
        l.valor_apagar                  = f.valor_apagar
        l.clientestipologiaanterior_id  = f.clientestipologiaanterior_id
        l.clientesobligacion_id         = f.clientesobligacion_id
        l.save

    end
非常感谢:)

我认为这将帮助您获得属性和值的列表

在此之后,您需要动态设置字段,为此您可以使用方法。大概是这样的:
@clientesultimasgestion.send(“{field\u name}=”,field\u value)

我将替换:

    @clientesultimasgestion.save(f)
与:


另外,似乎您想要的是复制一个表,请参见。

您可以使用
update\u属性保存许多行。
    @clientesultimasgestion.update_attibutes(f.attributes)