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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:23:28+00:00 2026-06-12T10:23:28+00:00

I have three models all associated with eachother via has_many :through method. ProgramCategory ProgramSubcategory

  • 0

I have three models all associated with eachother via has_many :through method.

ProgramCategory
ProgramSubcategory
Program

Inside my application, I need to use ProgramCategory.title, ProgramSubcategory.title and Program.title very often. Lets say, there’ll be a dynamic sidebar menu and it will look like this:

|- Shows (ProgramCategory)
  |- Action (ProgramSubcategory)
    |- Lost (Program)
    |- Games of Thrones (Program)
    |- Dexter (Program)

Since I’m aware of power of application_controller, application_helper and partials; I feel lost about combining all of these together to find the most appropriate way.

Where and how should I call my models? Where should I build my methods to have access it through all of my controllers? Should I simply create a partial and render it at application layout?

I need some expert enlightment, please…

Thanks.

  • 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-12T10:23:28+00:00Added an answer on June 12, 2026 at 10:23 am

    This navigation bar is not a core part of the data you are showing, it will be more or less the same for all pages. Thus, it does not belong to the controller.

    Make it a helper method, and cache its results in the view:

    app/helpers/sidebar_helper.rb

    module SidebarHelper
      def sidebar_data
        # blahblah, use any tag helper (include it here if necessary)
        # just remember to 
      end
    end
    

    app/controllers/your_controller.rb

    class YourController < ApplicationController
      helper :sidebar
      # ...
    

    (or put the helper method in your application helper to have it available everywhere)

    app/views/application/_sidebar.html.haml

    - cache do
      # well, put here whatever you need to output the sidebar
      # use the sidebar_data, which should return precooked data on 
      # which you can build your nested <ul>s.
      # just indent it two spaces, so it's inside the "cache do" block
    

    or app/views/application/_sidebar.html.erb

    <% cache do %>
      same as above, don't worry about indentation
    <% end -%>
    

    and include the partial where appropriate

    <%= render 'sidebar' %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have three models: class Address < ActiveRecord::Base has_many :jobs end class Category <
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I have three models: class A < ActiveRecord::Base has_many :bs end class B <
I have three Models with the associated properties: Links Model: var $belongsTo = array('LinkCategory');
I have three models, basically: class Vendor has_many :items end class Item has_many :sale_items
I have three models: User File Download User has_many Files , File belongs_to User
I have three models: User Image Group . User belongs to an image; Group
I have three models that are coming together to create one view model and

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.