tags:

views:

31

answers:

2

I'm using the following code..

$(document).ready(function(){   
    $("#test a").click(function(){
      var labelTo = $(this).text();
      window.location = '#{root_path(labelTo)}';

    });
 });

I just want to send the value labelTo in root_path..but its giving following error

undefined local variable or method `labelTo' for #

any solution??

A: 

The obvious thought that comes to mind is

window.location = '#{root_path(' + labelTo + ')}';

but what are those braces for?

Plynx
A: 

If root_path is a function which returns something then you can use like this

$(document).ready(function(){   
    $("#test a").click(function(){
      var labelTo = $(this).text();
      window.location = '#' + root_path(labelTo);
    });
});
rahul