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

  • Home
  • SEARCH
  • 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 1107505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:56:49+00:00 2026-05-17T01:56:49+00:00

Once my Rails 3 app is loaded, a user can click an item which

  • 0

Once my Rails 3 app is loaded, a user can click an item which needs to then load a dynamic subnav.

My thinking is (since it needs to be dynamic) is onClick to make a jQuery AJAX call to the server and then to inject the HTML response into a DIV on the page…

What I’d like your advice on is how/where the subnav logic should live in the rails app, as I don’t have a navigation controller or view… But maybe I should have one?

Do I create a navigation controller? Or use the application controller? I also have a pages controller that I use for the landing page, about, contact, etc…

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-05-17T01:56:50+00:00Added an answer on May 17, 2026 at 1:56 am

    For me, I would use a navigation controller rather than the application controller as the application controller growths extremely complex easily.

    This should create a view folder in app/views/navigation. I would also put all my navigation templates here (including you main nav).

    So there might be those files:

    app/views/navigation/
      _main_nav.html.erb # made it a partial file for including in other pages
      subnav.html.erb # or subnav.js.erb if you don ajax call and return scripts
    

    and in your layout files, where you want the main nav, you just render it.

    So even tomorrow you suddenly want two or three different navigation menus, and there ajax calls, you have a centralized place to handle them, instead of putting them all inside the application controller.

    Another more suggestion is, generate the navigation controller under some scopes. Like app/controllers/page_structures/navigation_controller.rb, so your views will be in app/views/page_structures/navigation/

    In this way, you could put all your page structure related things like sidebars, custom headers, banners, etc inside the same scope page_structures.

    ===== UPDATE =====

    Since your AJAX calls seems relatively static, I would suggest your paths use some kind of direct match.

    If my guess correct, your top navigation have some items, and each item has their own sub-menu. So you will want to load the sub-menu one by one but not all. (If actually it’s all, then you could just include them all in rendering…)

    /page_structures/:top_nav/:sub_nav_template_name # So in here I assumed you will have many navigations and sub-nav to load.
    

    then we match this path to the following action:

    def get_sub_nav
      # checks both params[:top_nav] and params[:sub_nav_template_name] exist and not pointing to some other dangerous place. (I don't know if this work if the input is './' or '../' these kind of things
      render "page_structures/navigation/#{params[:top_nav]}/#{params[:sub_nav_template_name]}"
    end
    

    By this simple action, whenever you added more navigation / navigation items, you just need to create the corresponding AJAX response template. in this way, you are doing the minimal things!

    Of course, if some how you have some items will need to return some other data as the response, such as responding sub-categories, you may need to create other routes to let you pass your parent category id.

    You could think like that: my suggestion is for the default relatively static centralized sub-nav
    But if you need some specialized sub-nav, which need other data to process, for each one you will have to create a route and an action in the navigation controller to accept your category id, product id, etc. But still, these template file could following the same filing way.

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

Sidebar

Related Questions

Running a rails site right now using SQLite3. About once every 500 requests or
Once a user starts a session (or logs in, for a registered user, to
Once again one of those: Is there an easier built-in way of doing things
Once I've created a variable in the immediate window in C# (VS2008), is there
Once again a very beginner-ish question, but here I go: I would like to
Once I have all the files I require in a particular folder, I would
Once a programmer decides to implement IXmlSerializable , what are the rules and best
Once it is compiled, is there a difference between: delegate { x = 0;
Once a controller object is created when does it become available for garbage collection?
Once a window has been closed, it is possible, and it is recommended, to

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.