jeudi 10 mars 2016

Pass javascript variable to ruby locals

I need to pass javascript variable to rails locals.

I have .js.erb file where I am fetching the post and comment number from the DOM through jquery. But I need to send this variable in rails locals.

Here is my .js.erb file code.

var label = $("#post_4375").find('label').text().split(")")[0].split(".");
var post_num = label[0];
var comment_num = label[1];

$("#post_"<%= @post.id %>).html('<%=j render partial: "comments/comment",  locals: { post: @post, comment: @comment, post_num: post_num, comment_num: comment_num } %>');

Is there any way to accomplish this?

There is another way that I will send this through params. But I not really want that way as this stuff is running conditionally.

Aucun commentaire:

Enregistrer un commentaire