15

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.

scientiffic
  • 9,045
  • 18
  • 76
  • 149
  • possible duplicate of [how to find the cause of ActiveRecord ROLLBACK](http://stackoverflow.com/questions/9060014/how-to-find-the-cause-of-activerecord-rollback) – lulalala Sep 25 '15 at 05:50

1 Answers1

28

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
Marek Lipka
  • 50,622
  • 7
  • 87
  • 91