{"id":90,"date":"2014-06-27T15:48:50","date_gmt":"2014-06-27T15:48:50","guid":{"rendered":"https:\/\/www.lianeallen.com\/home\/?p=90"},"modified":"2014-06-27T15:48:50","modified_gmt":"2014-06-27T15:48:50","slug":"the-mystery-of-the-uninitialized-constant","status":"publish","type":"post","link":"https:\/\/www.lianeallen.com\/home\/2014\/06\/the-mystery-of-the-uninitialized-constant\/","title":{"rendered":"The Mystery of the Uninitialized Constant"},"content":{"rendered":"<p>With error driven development, you see a lot of red and pink on your web site. The trick is to learn how to interpret what the message is trying to tell you. <\/p>\n<p>Most of them are pretty clear. If the word &#8220;path&#8221; appears, you&#8217;re probably missing something (or have a typo) in the routes list in your routes.rb file. If the word &#8220;relation,&#8221; or &#8220;table&#8221; appears, it&#8217;s probably the database. <\/p>\n<p>This one was less obvious to me (ignore the line highlighted in pinkish-red, and read the text at the top of the image):<\/p>\n<p><figure id=\"attachment_89\" aria-describedby=\"caption-attachment-89\" style=\"width: 916px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/uninitializedconstant.jpg\" alt=\"error message: uninitialized constant\" width=\"916\" height=\"202\" class=\"size-full wp-image-89\" srcset=\"https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/uninitializedconstant.jpg 916w, https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/uninitializedconstant-300x66.jpg 300w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption id=\"caption-attachment-89\" class=\"wp-caption-text\">the mystery uninitialized constant<\/figcaption><\/figure><br \/>\nI checked that the class existed, and that its name had no typos. I checked that it was being referenced correctly in the methods that needed it. <\/p>\n<p>I checked that the things that need it (and that it needs) had relations specifications (&#8220;has_many&#8221; and &#8220;belongs_to&#8221;) in the right files.<\/p>\n<p>I was stumped. So I asked for help. <\/p>\n<h3>And the answer is:<\/h3>\n<p>Model names are singular. The error message shows that the server was looking for a plural model name.<\/p>\n<p>Hmmmm, so where in the app is it being used in plural form?<\/p>\n<p>The model was properly defined, and its file name was correct, so &#8220;unwinding the stack&#8221; to the methods that use the model showed that they were also properly defined with no mystery plurals. <\/p>\n<p>The next step was to look at the places where relations were specified, and voila! There was a plural instead of singular in the Tagging class&#8217;s &#8220;belongs_to&#8221; relation.<\/p>\n<p>Yay!  It&#8217;s fixed, now.<\/p>\n<p>Here&#8217;s what should appear, instead of that error message:<\/p>\n<figure id=\"attachment_92\" aria-describedby=\"caption-attachment-92\" style=\"width: 241px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/Fixed.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/Fixed-241x300.jpg\" alt=\"image of an adorable rodent\" width=\"241\" height=\"300\" class=\"size-medium wp-image-92\" srcset=\"https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/Fixed-241x300.jpg 241w, https:\/\/www.lianeallen.com\/home\/wp-content\/uploads\/2014\/06\/Fixed.jpg 400w\" sizes=\"auto, (max-width: 241px) 100vw, 241px\" \/><\/a><figcaption id=\"caption-attachment-92\" class=\"wp-caption-text\">much cuter than an error message!<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>With error driven development, you see a lot of red and pink on your web site. The trick is to learn how to interpret what the message is trying to tell you. Most of them are pretty clear. If the word &#8220;path&#8221; appears, you&#8217;re probably missing something (or have a typo) in the routes list &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.lianeallen.com\/home\/2014\/06\/the-mystery-of-the-uninitialized-constant\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The Mystery of the Uninitialized Constant&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":91,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":10,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":103,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts\/90\/revisions\/103"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/media\/91"}],"wp:attachment":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}