Monday, April 25, 2011

That beautiful ArgumentError

Tonight while working on a mailer for the Depot application I'm developing with Agile Web Development with Rails, I screwed my code up and got this error.

I see errors similar to this one pretty often. Most of the time, I've made a typo or forgotten to close a tag or made a call on 'product' instead of '@product'. So I get frustrated when this screen pops up instead of the correct response I was hoping for, but one of the awesome things about Rails is it gives me some guidance on how to fix the error.

In this case, the error claims it's coming from the Orders Controller, but it was really coming from the mailer I created.

What was happening here is these methods aren't referencing anything. So the fix was to write the code like so:

I just skipped over this while working through the book, but if it was MY code, the error information Rails provides would still be valuable. In this case, the error wasn't actually in the Orders Controller, but it still pointed me in the right direction. The screenshot is a bit hard to read at this size (still trying to figure out the best way to display my code) but I'd forgotten to add (order) after defining both order_shipped and order_received.

My hope is I'll see less of these kind of syntax errors as I go along, but I have a feeling typos will be a continual problem.

No comments:

Post a Comment