fleshyorgans

tryin’ not to be a linux fanboy

fleshyorgans Two Cats

Note for the Rails debuggers

August 20th, 2006 · No Comments

I just spent an hour debugging something in vain — I have a Game model that has_many Players. The Player model belongs_to one Game.

In my controller, I wanted to do Game.new, then .build off the returned object. I kept getting undefined method ‘build’ and couldn’t figure out why. The method existed when I typed it all into script/console, just not from the web or breakpointer.

And then I noticed something. Scaffold screwed me over and pluralized all my models. Thus all the new statements in the scaffolded controller were pluralized. Thus, I had no relations set up, since I’d only added them to the correctly singularized model name files. Games.new is very different from Game.new when you’ve only said has_many in game.rb

Lastly, the reason I didn’t notice this is because Eclipse doesn’t do a live update for newly created files…. Anytime you create new files you have to select your dir and hit refresh. I’d generated my models by hand, then ran scaffold after I’d loaded up the Eclipse editor. As well, I missed the extra ’s’ in the controller references.

So anyway, if your associations don’t appear to be building properly, make sure scaffold hasn’t screwed up your names for you.

No tag for this post.

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment