{"id":1323,"date":"2022-08-30T15:15:34","date_gmt":"2022-08-30T15:15:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/nomethoderror-undefined-method-scoped-for-classmodule-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:34","modified_gmt":"2022-08-30T15:15:34","slug":"nomethoderror-undefined-method-scoped-for-classmodule-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/nomethoderror-undefined-method-scoped-for-classmodule-collection-of-common-programming-errors\/","title":{"rendered":"NoMethodError (undefined method `scoped&#39; for Class:Module):-Collection of common programming errors"},"content":{"rendered":"<p>I have a has_many and has_many :through relationship that looks like this&#8230;<\/p>\n<pre><code>class Guestlist &lt; ActiveRecord::Base\n    belongs_to :venues\n\n    has_many :patrons\n    has_many :users, :through =&gt; :patrons\n\n    attr_accessible :capacity, :end_time, :name, :start_time, :venue_id\nend\n\nclass Patron &lt; ActiveRecord::Base\n    belongs_to :guestlists\n    belongs_to :users\n    attr_accessible :guestlist_id, :user_id, :checked_in\nend\n\nclass User &lt; ActiveRecord::Base\n  devise :database_authenticatable, :registerable,\n         :recoverable, :rememberable, :trackable, :validatable\n\n  attr_accessible :name, :email, :password, :password_confirmation, :remember_me\n\n  has_many :patrons\n  has_many :guestlists, :through =&gt; :patrons\nend\n<\/code><\/pre>\n<p>I am trying to access the users &#8220;through&#8221; guestlist object&#8230;<\/p>\n<pre><code>@guestlist = Guestlist.find(params[:id])\n@guests = @guestlist.users.order('name ASC')\n<\/code><\/pre>\n<p>and the following error is thrown&#8230;<\/p>\n<pre><code>NoMethodError (undefined method `scoped' for Users:Module)\n<\/code><\/pre>\n<p>I&#8217;ve been searching all over for a solution but nothing works. Please help!<\/p>\n<ol>\n<li>\n<p>Looks something wrong with your associations in Model <code>Patron<\/code>. Singularize <code>users<\/code> and <code>guestlists<\/code>. Refer more here<\/p>\n<pre><code>class Patron &lt; ActiveRecord::Base\n    belongs_to :guestlist \n    belongs_to :user\n    attr_accessible :guestlist_id, :user_id, :checked_in\nend\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:16:55. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a has_many and has_many :through relationship that looks like this&#8230; class Guestlist &lt; ActiveRecord::Base belongs_to :venues has_many :patrons has_many :users, :through =&gt; :patrons attr_accessible :capacity, :end_time, :name, :start_time, :venue_id end class Patron &lt; ActiveRecord::Base belongs_to :guestlists belongs_to :users attr_accessible :guestlist_id, :user_id, :checked_in end class User &lt; ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, [&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-1323","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1323","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=1323"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1323\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}