{"id":427,"date":"2022-08-30T15:01:10","date_gmt":"2022-08-30T15:01:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/ruby-on-rails-rake-routes-giving-error-about-a-model-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:01:10","modified_gmt":"2022-08-30T15:01:10","slug":"ruby-on-rails-rake-routes-giving-error-about-a-model-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ruby-on-rails-rake-routes-giving-error-about-a-model-collection-of-common-programming-errors\/","title":{"rendered":"Ruby on Rails &#8211; rake routes giving error about a model-Collection of common programming errors"},"content":{"rendered":"<p>I have this model:<\/p>\n<pre><code>class Kpi\n  include Mongoid::Timestamps\n  #include Mongoid::Document\n\n  field :number_of_users,      :type =&gt; Integer, :default =&gt; 0\nend\n<\/code><\/pre>\n<p>and when I ran rake routes, I got this error:<\/p>\n<pre><code>rake aborted!\nundefined method `field' for Kpi:Class\n<\/code><\/pre>\n<p>any idea why that would happen?<\/p>\n<p>Thanks!<\/p>\n<ol>\n<li>\n<p><code>rake routes<\/code> loads your environment -&gt; loads your code. So if there&#8217;s an error in your code, it won&#8217;t show your routes. In your case, you should uncomment <code>include Mongoid::Document<\/code><\/p>\n<p>EDIT<\/p>\n<p>So it&#8217;s not working even with it ? Hm, maybe include <code>Document<\/code> before <code>Timestamps<\/code> ? Kind of a long shot here<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:41:34. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have this model: class Kpi include Mongoid::Timestamps #include Mongoid::Document field :number_of_users, :type =&gt; Integer, :default =&gt; 0 end and when I ran rake routes, I got this error: rake aborted! undefined method `field&#8217; for Kpi:Class any idea why that would happen? Thanks! rake routes loads your environment -&gt; loads your code. So if there&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-427","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}