title: Loop through rails associations
body: <p>1)I'm trying to create a site that has several restaurants each having their own unique menu being displayed in a table, the association works in the console but not in code.I loop over the @restaurant instance variable then in the table I put the data I want from the menu so restaurant.menu.dish but getting an error that 'each' is undefined even though I didn't state a one-one relationship.How may I carry out the desired behavior?</p>
  
  <p>2) How do I ensure that the menu data corresponds with the right restaurant,I'm assuming that the show controller saves the restaurant variable with a specific ID and calling a method like .dish would know what restaurant based on the show action variable, is this correct thinking?</p>
  
  <p>Restaurant Model</p>
  
  <pre><code>class Restaurant &lt; ActiveRecord::Base
  
    has_attached_file :thumbnail, styles: { medium: "300x300&gt;", thumb: "100x100&gt;" }, default_url: "/images/:style/missing.png"
    validates_attachment_content_type :thumbnail, content_type: /\Aimage\/.*\Z/
    has_many :menus
  
    def self.search(search)
      if search
      @restaurants= Restaurant.where("name LIKE ?", "%#{search}%")
      else
        @restaurants=Restaurant.all
      end  
    end
  end
  </code></pre>
  
  <p>Menu Model</p>
  
  <pre><code>class Menu &lt; ActiveRecord::Base
    belongs_to :restaurant
  end
  </code></pre>
  
  <p>Restaurant controller with show action </p>
  
  <pre><code>def show
    @restaurant = Restaurant.find(params[:id])
  end
  </code></pre>
  
  <p>Show.html.erb</p>
  
  <pre><code>&lt;div class="col-md-8"&gt;
    &lt;table class="table table-striped"&gt;
      &lt;h3&gt;Menu&lt;/h3&gt;
      &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Dish&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;th&gt;Calories&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
      &lt;tbody&gt;
      &lt;%= @restaurant.each do |restaurant| %&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;%= restaurant.menu.dish %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= restaurant.menu.price %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= restaurant.menu.price %&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;&lt;td&gt;..&lt;/td&gt;&lt;td&gt;..&lt;/td&gt;&lt;td&gt;..&lt;/td&gt;&lt;/tr&gt;
      &lt;% end %&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>