Note that there are some explanatory texts on larger screens.

plurals
  1. PORails newbie - am I missing something really obvious?
    text
    copied!<p>Quite experienced but self taught with PHP/MySQL and playing about with Rails. Really love what i've done with it do so far but am seriously struggling with what in my mind should be really simple; joining data from various tables together and then displaying it in various views. I think I get the concept of Active Record, I just can't seem to get it to work they way I want.</p> <p>I'm working on building a fairly involved music cataloging system ala Discogs, with artist, release, product, track and label levels and have the following models:</p> <pre><code>class Artist &lt; ActiveRecord::Base has_and_belongs_to_many :releases end class Release &lt; ActiveRecord::Base has_many :products end class Product &lt; ActiveRecord::Base belongs_to :release has_many :tracks end class Tracks &lt; ActiveRecord::Base has_and_belongs_to_many :products end </code></pre> <p>Eventually, I want to introduce territories, sales and other data but until I nail the basics above I can't move fwd.</p> <p>In my products controller I have:</p> <pre><code>@product = Product.find(:all, :include =&gt; :release) </code></pre> <p>Which produces:</p> <pre><code>Processing by ProductsController#index as HTML Product Load (0.1ms) SELECT "products".* FROM "products" Release Load (0.2ms) SELECT "releases".* FROM "releases" WHERE "releases"."id" IN (1, 2, 3, 10, 4) </code></pre> <p>But I am thinking this might be unnecessary if my associations are correct? </p> <p>In my products view for example I want to list products with the title pulled in from the releases table. I've tried the following but get a 'NoMethodError' on title:</p> <pre><code>&lt;% @product.each do |product| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= product.title %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= product.cat_no %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= product.barcode %&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; </code></pre> <p>Help!!</p> <p>Massive thanks in advance.</p> <p>Ryan</p>
 

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