Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:29:38+00:00 2026-05-27T17:29:38+00:00

This has been driving me crazy. I’ve done lots of google and stackoverflow searches

  • 0

This has been driving me crazy. I’ve done lots of google and stackoverflow searches but can’t find a solution. I have 2 models: FoodMenu and Product. FoodMenu has_many :products and Product belongs_to :food_menu. The products table has a “food_menu_id” column and I’ve also done add_index :products, :food_menu_id.

I want to create a view that lists all FoodMenus and their Products. In the views folder I have a pages folder that contains “menus.html.erb”. In pages.controller.rb, I have:

def menus
@food_menus = FoodMenu.includes(:products).all
end

In menus.html.erb, I have:

<%= @food_menus.each do |food_menu| %>
  <%= food_menu.name %>
    <ul>
       <%= food_menu.products.each do |product| %>
         <li><%= product.name %></li>
       <% end %>
   </ul>
<% end %>

This returns the expected data, except that after each set of products, it also displays the full array of products, and then at the end, it displays the full array of FoodMenus. Why is it doing that and how can I fix it?

By full array, I mean this:
[#FoodMenu id: 1, name: “Sandwiches”, description: “right off the press”, created_at: “2011-12-21 20:39:42”, updated_at: “2011-12-21 20:39:42″>, #FoodMenu id: 2, name: “Pizza”, description: “fresh local dough”, created_at: “2011-12-21 20:40:03”, updated_at: “2011-12-21 20:40:03″>]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:29:38+00:00Added an answer on May 27, 2026 at 5:29 pm

    The each should look like this:

    <% food_menu.products.each do |product| %>
    

    each returns the enumeration it was called on (the “array”, although it’s not a real array).

    <%= %> renders the value inside it. In this case, the array-looking thing–the return value of each.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving be crazy, but I can't seem to find an answer.
This has been driving me crazy because I can't find anything on Google. Maybe
This has been driving me crazy. I think I have everything in place but
This has been really driving me crazy. Web links work fine, but a phone
Maybe this is an easy fix, but it has been driving me crazy for
This has been driving me crazy for the past few days. I've done something
I hope someone can help me. This has been driving me crazy for days.
This has been driving me crazy for a few days. Why doesn't the following
This has been driving me crazy for the past few minutes I have a
so I am having this issue that has been driving me crazy for hours,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.