Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamic content with ajax (ruby on rails)

I am using Rails and jquery, and I need a dynamic content with ajax.

But I don't know how to get the current user ID

For example the url is www.mywebsite.com/users/20

In my javascript file I need the user ID (20)

$.get("/users/<%= **20** %>.json", function(data)
      {

      }, "json");

Thanks in advance for any help.


Is there another way to do this ?

like image 215
user1560922 Avatar asked Jul 30 '12 17:07

user1560922


1 Answers

Generally i put a hidden field with the id somewhere in the page, where i can easily access with $("#user_id") on the javascript file, then the request would be something like this:

var id = $("#user_id").val();
$.get("/users/"+id+".json", function(data) { }, "json");
like image 76
MurifoX Avatar answered Sep 24 '22 05:09

MurifoX