mardi 4 août 2015

In rails, the instance of the model doesn't show up in my table. What is happening when the console says "COMMIT" and "=>true"?

I am pretty new to Ruby on Rails and I'm having some problems. I have already checked out: This stackoverflow question about cloning a model

I am creating a new method for a model that looks like this:

def copy(new_period)
@copy = self.clone
@copy.report_id = Report.maximum(:report_id).next
@copy.period_id = new_period
@copy.save
end

I am trying to create a new instance of report that can be moved to the next year(period). When I run this method in irb I get:

irb(main):003:0> c = r.copy(5)

(1.8ms) SELECT MAX("reports"."report_id") AS max_id FROM "reports"

(0.8ms) BEGIN

(1.0ms) UPDATE "reports" SET "period_id" = 5 WHERE "reports"."report_id" = 438

(1.1ms) COMMIT

=> true

When I look in pgAdmin the new report isn't there. Could someone please explain to me what is going on when the console says "commit" and "=> true"? Does this not mean it has saved to the database?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire