I am having trouble with passing the correct data from my rails html.erb view file to my js file.
I have the following in my controller (@messages = Message.all) and in my html.erb view file:
@messages.each do |x|
x.name
end
if i have a javscript file how do i pass the id of the specific message to it?
I am trying this:
@messages.each do |x|
<span id="messageid" data-id="<%= x.id %>">
<%=x.name%>
</span>
end
and in my javascript file:
$("#messageemail").click(function(){
var messageid = $("#messageemail").data('id');
alert(messageid);
this partially works, but it only gives me the id for the first message in the list. I want it to give me the specific id of which ever message is clicked
messageemailid?