JQuery AJAX to Rails 3, In Rails, how to get a variable passed through data?

Rails 3 app .... I have the following jQuery that works:

$.ajax({ url: '/navigations/sidenav', data: "urlpath=" + urlpath, success: function(e){ $("#sideNav-container").slideDown("slow"); } }); 

urlpath can be types like "/" or "/ projects" or "/ author".

My question is: how can I grab this urlpath variable in the controller so that I can use it in my view to determine which sidenav will be returned to the user?

thanks

+4
source share
1 answer

Go to urlpath in the hash for the data key. For instance:

 $.ajax({ url: '/navigations/sidenav', data:{"urlpath":urlpath}, success: function(e){ $("#sideNav-container").slideDown("slow"); } }); 

Then, the urlpath in the params object will be passed, which you can access from your controller. Therefore you can just do

 params[:urlpath] 

and you can get the urlpath you went to. :)

+2
source

All Articles