scientiffic
scientiffic

Reputation: 9415

View cause of rollback error in rails console

I'm trying to update a record through the rails console and am getting a rollback error:

Project.find(118).update_attributes(:featured=>true)
  Project Load (2.6ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1  [["id", 118]]
   (2.8ms)  BEGIN
   (1.3ms)  ROLLBACK
=> false

How can I view the source of the error? I'm able to update the attribute for other records, so I'd like to inspect why this particular record isn't working.

Upvotes: 15

Views: 7862

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51171

Your Project instance is probably invalid. To see what error prevented it from saving, you can type:

project = Project.find 118
project.assign_attributes(featured: true)
project.valid?
project.errors.full_messages

Upvotes: 28

Related Questions