Active Nil ID

20 views
Skip to first unread message

Jan Yo

unread,
Sep 30, 2014, 9:18:42 PM9/30/14
to rubyonra...@googlegroups.com
I do a create on an Active Record model in a controller and it's doing
something strange. It's primary key (id) is nil, created/updated are
nil as well.

A few of the columns/attributes are nil as well. The model instance
gets created but the id is nil.

Rspec fails for the model because its id is nil (because it's being
passed to other models)

Any ideas?

--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Oct 1, 2014, 2:11:57 AM10/1/14
to rubyonra...@googlegroups.com


On Wednesday, October 1, 2014 2:18:42 AM UTC+1, Ruby-Forum.com User wrote:
I do  a create on an Active Record model in a controller and it's doing
something strange.  It's primary key (id) is nil, created/updated are
nil as well.


That sounds like the model wasn't saved. Probably a failed validation or a before_save that returned false.

Fred 

Jason Fleetwood-Boldt

unread,
Oct 1, 2014, 10:03:09 AM10/1/14
to rubyonra...@googlegroups.com

Debug the code directly using debugger, binding or pry.

try this (assuming thing is your variable)

thing.save

You should see a message "false" telling you that the object wasn't saved

then type

thing.errors

and you should see what the validation errors are
-Jason

Jan Yo

unread,
Oct 1, 2014, 10:52:54 AM10/1/14
to rubyonra...@googlegroups.com
That was it ! Thanks!
Reply all
Reply to author
Forward
0 new messages