I recently wanted to add a highlight link to a navigational element if the navigation was on the current page. I thought this would be pretty straight forward with Rails’ link_to helper. Turns out it was a little less-than-intuitive. So, to remind myself (and show others) how to do this, I’m providing the following:
In my research, I saw different ways of going about this, but this apparently is the recommended method as it’s in the documentation (see the URLHelper).
I have to say this seems a bit counter-intuitive and not as “easy” as it should be. I kept expecting to be able to do something like:
Anyway, if you want to add a highlight class, this works.