Selected menu item in the layout

Hi you all,

I have a basic menu in my index page which is always shown (Home-New
page-List pages, etc.)
This menu list is therefore on the layout of the app. However, I would
like to change the color (the class from the CSS) of any item when this
is the current selected item.
The basic way is asking for the “controller.action_name” and make a
biiig “if” sentence to manage the possibilities:
If controller.action_name=”new_page” then

  • Home
  • New page
  • List pages
  • Else If...

    Is there any other short way?
    Thanks

    Well you can use link_to_unless_current, but you won’t get
    class=“selected”. Instead you’ll have to code your CSS based on the
    existence of a link or not.

    On May 24, 10:20 am, Damaris F. <rails-mailing-l…@andreas-

    dasil003 wrote:

    Well you can use link_to_unless_current, but you won’t get
    class=“selected”. Instead you’ll have to code your CSS based on the
    existence of a link or not.

    On May 24, 10:20 am, Damaris F. <rails-mailing-l…@andreas-

    Thanks! That did work! and just with one or two changes in my CSS :smiley:

    Damaris F. wrote:

    dasil003 wrote:

    Well you can use link_to_unless_current, but you won’t get
    class=“selected”. Instead you’ll have to code your CSS based on the
    existence of a link or not.

    On May 24, 10:20 am, Damaris F. <rails-mailing-l…@andreas-

    Thanks! That did work! and just with one or two changes in my CSS :smiley:

    Um, the thing is that, apart from this menu (I have it at the top, as
    tabs), in each option I can have a submenu (a set of links at the left).
    In this case, when I select one of this suboptions, the menu above get
    unselected… :-S

    Right well, in that case you need to do something more robust anyway
    because you’ll want the tab to be an active link when you are on any
    of the subpages.

    However, you can create a helper that will emulate
    link_to_unless_current with your own semantics so your template
    doesn’t get bloated.

    On May 27, 2:32 pm, Damaris F. [email protected]

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs