Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 895
scientiffic Avatar asked Oct 04 '13 18:10

scientiffic


1 Answers

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
like image 173
Marek Lipka Avatar answered Nov 05 '22 10:11

Marek Lipka