{"id":274,"date":"2013-09-04T17:58:27","date_gmt":"2013-09-04T23:58:27","guid":{"rendered":"http:\/\/sha.nnoncarey.com\/blog\/?p=274"},"modified":"2016-03-04T17:59:04","modified_gmt":"2016-03-04T23:59:04","slug":"rails-antipatterns","status":"publish","type":"post","link":"https:\/\/sha.nnoncarey.com\/blog\/archives\/274","title":{"rendered":"Rails antipatterns"},"content":{"rendered":"<p>This unfinished post hails from 2013. Is any of it still true? No idea.<\/p>\n<p><strong>accepts_nested_attributes_for<\/strong> (use view models)<\/p>\n<p><strong>instance variables in the application controller<\/strong> &#8211; every controller and every view can see it. There&#8217;s no great place to put an object that lives for the whole request (in the request? in the response? in an object temporarily in the config?) People like Mongoid&#8217;s IdentityMap end up using static methods with thread locals for thread safety&#8230; that&#8217;s not a great way to do it.<\/p>\n<p><strong>Error messages put together in models, and i18n as the only alternative<\/strong> &#8211; Many people construct error messages directly in the model. In the best case, they may use the built-in i18n support to provide parameters to be substituted into a phrase. However, the model is still responsible for formatting the objects as appropriate in order to be substituted into the i18n string. If, for example, you need to include a list of objects in the error which should then be formatted to a more complex string (for example, a link to the article), it is not easy to make use of a view or helper to perform that functionality for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This unfinished post hails from 2013. Is any of it still true? No idea. accepts_nested_attributes_for (use view models) instance variables in the application controller &#8211; every controller and every view can see it. There&#8217;s no great place to put an object that lives for the whole request (in the request? in the response? in an &hellip; <a href=\"https:\/\/sha.nnoncarey.com\/blog\/archives\/274\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Rails antipatterns&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":5,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":368,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions\/368"}],"wp:attachment":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}