Note that there are some explanatory texts on larger screens.

plurals
  1. PObelongs_to with multiple models
    primarykey
    data
    text
    <p>I am a Rails noob and have a question. I have a feed aggregator that is organized by this general concept:</p> <p>Feed Category (books, electronics, etc) Feed Site Section (home page, books page, etc) Feed (the feed itself) Feed Entry</p> <p>So: </p> <pre><code>class Category &lt; ActiveRecord::Base has_many :feeds has_many :feed_entries, :through =&gt; :feeds, :limit =&gt; 5 validates_presence_of :name attr_accessible :name, :id end class Section &lt; ActiveRecord::Base has_many :feeds has_many :feed_entries, :through =&gt; :feeds, :limit =&gt; 5 attr_accessible :name, :id end class Feed &lt; ActiveRecord::Base belongs_to :categories belongs_to :sections has_many :feed_entries validates_presence_of :name, :feed_url attr_accessible :name, :feed_url, :category_id, :section_id end class FeedEntry &lt; ActiveRecord::Base belongs_to :feed belongs_to :category belongs_to :section validates_presence_of :title, :url end </code></pre> <p>Make sense? Now, in my index page, I want to basically say... If you are in the Category Books, on the Home Page Section, give me the feed entries grouped by Feed...</p> <p>In my controller:</p> <pre><code>def index @section = Section.find_by_name("Home Page") @books = Category.find_by_name("Books") end </code></pre> <p>In my view:</p> <pre><code>&lt;%= render :partial =&gt; 'feed_list', :locals =&gt; {:feed_group =&gt; @books.feeds} -%&gt; </code></pre> <p>This partial will spit out the markup for each feed entry in the @books collection of Feeds. Now what I need to do is somehow combine the @books with the @section...</p> <p>I tried this:</p> <pre><code>&lt;%= render :partial =&gt; 'feed_list', :locals =&gt; {:feed_group =&gt; @books.feeds(:section_id =&gt; @section.id)} -%&gt; </code></pre> <p>But it isn't limiting by the section ID. I've confirmed the section ID by using the same code in the console...</p> <p>Make sense? Any advice?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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