Onclick/javascript For Div; Rails Iterator
I have a directory page where the listings are rendered on the index page. <% @listings.each do |listing| %> # do some stuff <% end %> I've added a data-toggle to ea
Solution 1:
Not to sure what you mean by "use that ID throughout the div." but you could try this if it helps you?
<div data-id="<%=listing.id %>"class="chat-window-wrapper">
If you want to get the id's value from what ruby printed then you can try adding an event listener
$(".chat-window-wrapper").on("click",function() {
var x = parseInt($(this).attr('data-id');
}
To access listings outside iterator try
listings[index]
or
@allListings = listings. Then access @allListings[index]
but as far as my rusty ruby knowledge goes, i think listings should be accessible as long as the controller is passing it in the context to the view.
Post a Comment for "Onclick/javascript For Div; Rails Iterator"