I want to take the value of a js variable, and have it available in my rails view without having to refresh the page. I'm not sure if this is even the best way to go about it.
I have a varying amount of titles that can be clicked. When one is clicked, I want to grab the value of that and pass it to a div that displays info about the object clicked.
#drafts
- @posts.all.each_with_index do |post, index|
= link_to strip_tags(post.title), "#", id: "post#{index}"
#post-view
.title-editor
= post_that_was_clicked.title
hr
.body-editor
= post_that_was_clicked.body
js:
$('#drafts').click(function(e) {
var txt = $(e.target).text();
alert(txt);
});
How can I accomplish this?