Accessing a passed variable from JQuery to Rails controller
I have this JQuery code:
$("div.notification").live("click", function(){
window.location=$(this).find("a").attr("href");
var myId = $(this).attr("id");开发者_如何学Python
$.post("/videos/selected_notification.js", myId);
return false;
});
I want to be able to access myId
from inside my controller that the post request hits. How do I do this?
Give your myId
value a name and you can pull it out of params
just like any other POST parameter:
$.post("/videos/selected_notification.js", { id: myId });
And then, in the controller:
id = params['id'] # Or params[:id] since params is a HashWithIndifferentAccess
精彩评论