Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

Ben Unsworth's Profile

GitHub User: bunswo

Site: www.globacore.com

Comments by Ben Unsworth

Avatar

I have an odd case where my code created with the help of this rails casts for HABTM checkboxes was working fine... an then all of a sudden I'm getting a NoMethodError: undefined method `name' for nil:NilClass error when creating or updating a record that has project_ids filled in.

If I try to use the method in the rails console I get the error specifically at the point of adding project_id's like this:

p = Project.last

works and returns project field data

p.person_ids = [1,2]

  1. runs 3 SQL statements, selecting the person, selecting through a join my assignment of the person to the project, and then inserting the assignment
  2. then it says rollback transaction
  3. and displays the method NoMethodError: undefined method `name' for nil:NilClas

And the weird part is, that once that all happens, if I call p.save after the errors list, it actually saves properly adding the two people assignments to the project

I've rolled back the git history to see if I did something else, but even if I go way back to previous versions that worked for sure it still gives the same error. This makes me think it's database related??