Give each li an id (i.e. app_nav_li_projects, app_nav_li_files)
Set @li_to_select in your controller or controller method to the li id
you
want to select
Use JQuery on the page to add the selected class to the li id of the
@li_to_select
My JQuery looks like this:
<script type="text/javascript">
// Adds the current class to the requested app nav menu
$(document).ready(function(){
$("li#<%= @li_to_select%>").addClass("selected");
});
</script>
Terrible. As I've said numerous times on this forum, dynamic JS -- and
inline JS even more so -- are problematic from a design standpoint and
should always be avoided. What you should be doing here is using an
external JS file to which you pass the ID by a method such as having it
look in the DOM.
But I'm not sure this is the right approach. Rails provides a bunch of
helpers such as current_page? and link_to_if_current_page, so it seems
to me that you should be able to do this on the server side.
Thanks all. I have no intention of wanting to do this client-side with
JS... Only Server Side... Any suggestions? Seems like this is
something every RAils app needs solved?
Thanks all. I have no intention of wanting to do this client-side with
JS... Only Server Side... Any suggestions? Seems like this is
something every RAils app needs solved?
Yes. Read my previous post, where I explained how to do it server-side.