Note that there are some explanatory texts on larger screens.

plurals
  1. PONameError: uninitialized constant - Un-allowed syntax in ActiveRecord?
    text
    copied!<p>I have two resources that I'm trying to join - Package and Listing through a join table SubmittedPackage. I'm using Ruby 1.9.3-p125 and Rails 3.2.1 with PostgreSQL 9.1.3. The models look as follows.</p> <pre><code>class Package &lt; ActiveRecord::Base has_many :submitted_packages has_many :listings, :through =&gt; :submitted_packages class Listing &lt; ActiveRecord::Base has_many :submitted_packages has_many :packages, :through =&gt; :submitted_packages class SubmittedPackages &lt; ActiveRecord::Base belongs_to :package belongs_to :listing </code></pre> <p>In Rails Console I keep getting <em>NameError: uninitialized constant Listing::SubmittedPackage</em></p> <p>If I replace the <em>SubmittedPackage</em> resource with <em>Drum</em> it will work (this of course includes having the appropriate table created and so forth).</p> <p>Is :submitted_packages in conflict with something in Rails or ActiveRecord?</p> <p>Any ideas why this is breaking?</p> <p>Thanks in advance!</p> <p>UPDATE: As a work-around I explicitly defined the :class_name for the has many relationship in the Listing and Package model. This has at least gotten things working, however, it's still is unclear to me why it was necessary to begin with. What Rails or Ruby naming convention was being broken by <code>:submitted_packages</code> ?</p> <pre><code>class Package &lt; ActiveRecord::Base has_many :submitted_packages, :class_name =&gt; 'SubmittedPackages' has_many :listings, :through =&gt; :submitted_packages class Listing &lt; ActiveRecord::Base has_many :submitted_packages, :class_name =&gt; 'SubmittedPackages' has_many :packages, :through =&gt; :submitted_packages class SubmittedPackages &lt; ActiveRecord::Base belongs_to :package belongs_to :listing </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload