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 8934949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:53:16+00:00 2026-06-15T09:53:16+00:00

I want to make a rollOver menu for my project’s main page. This will

  • 0

I want to make a rollOver menu for my project’s main page. This will be shown in all pages of the site. Main menu items are SHOWS and PROGRAMS. When someone rolls over those buttons, all programmes will be listed inside a popping up div. (Program is name of my model and it’s a general name I use for both shows, movies, tv programs etc.)

Now…

Here are my associations:

Program.rb

class Program 
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title
  field :content

  belongs_to :program_category

end

program_category.rb

  class ProgramCategory 
    include Mongoid::Document
    include Mongoid::Timestamps

    field :title
    field :content

    has_many :programs

  end

I need to get program.titles to show inside my menu. Like this:

SHOWS         PROGRAMS
  \- Lost        \- Ellen
  \- Dexter      \- Marta Stuart
  \- Alf         \- Jey Leno Show

Well… I’m doing this like this now:

home_controller.rb

class HomeController < ApplicationController

 def index
     @menu_programs = Program.all.where(program_category_id: "50a7c373ce3a6bcc0a000006").limit(10)    #Yes, i think it's lame too...
     @menu_shows = Program.all.where(program_category_id: "50a67f36ce3a6b840d000007").limit(10) # And yes I'm using MonoDB and Mongoid
  end

Yeah… They are program_category_ids and very hard coded!!

I feel like…

This is not the best practice!

QUESTION is:

What is best practice to show menu items from associated models? I heard somethign called ‘Eager Loading’ can someone explain it please? Because of n + 1 problem I have 36 queries…

Any suggestion is welcomed.

Thank you.

  • 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-06-15T09:53:17+00:00Added an answer on June 15, 2026 at 9:53 am

    The answer of What is best practice to show menu items from associated models? question is:

    Using Fragment Caching, I think. It’s even more essential than eager loading IMHO.

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

Sidebar

Related Questions

I want make a page (HTML + CSS) that fits all the space left
I want make submit in this page http://www.enviarsmsacuba.com/?p=join with C# and webbRowser controll but
I want make datetimepicker in my project. Using jquery how it is possible? I
I want make a simple referral system. Basically referral URL structure something like this.
i want make function like that function(data){ } i want this data as this
i want make a popup window for login/signup. so i'v written this code. but
I am newer for php. I want make php page cache, query data from
I want make sql query which will insert values from one table to another
i want make my view transparent show the the previous view will slightly visible,i
i want make a news site gets its content from other news sites, open

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.