Controlling outer divs on 3rd level menu, and adjusting layout accordingly

Skip to first unread message

Mar 8, 2013, 11:22:01 PM3/8/13
Hi folks, am pretty new to RoR and programming (2 weeks in!), and am using this gem to generate a menu structure in an admin namespace. 
We have 3 or 4 levels of nested menu, depending on options chosen.

Heres a chunk of the layout:

                           <div class="row">
                                <div class="span2">
                                    <%= render_navigation( :context => :admin, :level => 1) %>
                                <!--! and :admintop-->
                                <div class="span10">
                                    <%= render_navigation( :context => :admin, :level => 2) %>
                            <!--! This row is for the yield of menu items! -->
                            <div class="row subnavonly">
                                <div class="span2">
                                    <%= render_navigation( :context => :admin, :level => 3) %>                                   
                            <div class="row content">
                                <div class="span10">
                                    <%= yield %>   

I need to render a different width row, containing the yield dependent on the existence of level 3 (and sometimes 4th) menus.
Ideally I would like to adjust / set the class of '.content div' between span10 and span12 accordingly.
I need to make sure I dont render the divs around the 3rd level when its empty.

I think my choices are:

Work out how to dynamically include the <div class="row"><div class="span2"> and matching closing tags around the outside of the ul that the third level would generate -- and if its missing not render them at all.

Work out how to test for the existence of 3rd level items and load a differnet partial containing a different output in each case (with/without lvl 3)

Find a way to insert a partial containing the sub_sub_nav inside the yield (content_for ?), and only render it if used - I will have different controllers and many different yields however.

I should probably also note - that as soon as I learn how I want to change all the links to be ajaxified using remote => true (I mention in case it impacts on the 'best' solution)
The content rendered in yield may itself have links and actions that need to stay rendered within that yield and not break out (unsure if that is relevant)

Am I missing anything obvious, and how should I approach it ?

Many thanks for a great gem!


Andi Schacke

Mar 9, 2013, 2:46:18 AM3/9/13
Hi Mizpah,

welcome to the Rails community. First of all, your layout seems pretty complex. If a layout / page structure is really complex, always try to find a way to simplify it. I'm not saying that you shouldn't do it, but always try to work on solutions that are simple and easy to maintain. That said, I think in your case I would make use of the helper method 'active_navigation_item' to check for existence of level 3 navi and then render your content accordingly.

When it comes to ajax, be aware that highlighting the active navigation item does not work anymore because the navigation is not rerendered. So if you click on your primary nav and load your content for that item using ajax, you have to manually set the active navigation item in your primary navigation using javascript (which is pretty easy because you are actually clicking the item, so you just have to handle that in an onclick handler). Or you have to rerender the primary navigation on the server and insert it on your success callback.

Hope that helps.

You received this message because you are subscribed to the Google Groups "simple-navigation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Martin Dean

Mar 11, 2013, 7:56:15 AM3/11/13

Many thanks Andi!

I have to say the level of feedback and support within the rails community as a whole is a very welcoming experience!  I am sure I will have some more questions later, as I have a spec that calls for people adjusting menus to their own user preferences (i.e. drag/drop icons of choice to a given menu), but for now that has me up and running!

You received this message because you are subscribed to a topic in the Google Groups "simple-navigation" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
Reply all
Reply to author
0 new messages