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.