Convert to hash or upload to database - Ruby on rails

0

I have this that I took out of my database with:

nombre_secciones = Section.where(quotation_id: quotation_id_event)

I got this out:

#<Section id: 12, name: "Seccion 1", created_at: "2018-07-24 15:06:34", updated_at: "2018-07-24 15:06:34", quotation_id: 62, order: 0>

I have already made the changes I want but now I want to upload it back to my database but in a new row but I do not know very well how or how could I transform it into a hash?

    
asked by AlexCs 25.07.2018 в 17:50
source

1 answer

0
  

... but now I want to upload it back to my database but in a   new row ...

The answer is in the first question you published on this same topic; you can see it here .

  

... how could I transform it into a hash?

You can use the as_json method, which will return an array of hashes . where each hash is a record / row of the model in the database:

Section.where(quotation_id: quotation_id_event).as_json
#[{"id"=>12, "name"=>"Seccion 1", "created_at"=>"2018-07-24 15:06:34", "updated_at"=>"2018-07-24 15:06:34", "quotation_id"=>62, "order"=>0}]
    
answered by 29.07.2018 в 08:23