I need to get the value of a parameter in a javascript code and pass it on to a rails partial view but it won't let me do that. Here is what I have:
<div id="myCarousel" data-carousel-3d>
<% @users.each do |user| %>
<input type="image" src="/assets/<%= user.location %>" data-toggle="modal" data-target="#modal-1" />
<% end %>
</div>
<script>
$('#myCarousel').on('select', function (evt, index) {
var myHtml = "<\%= escape_javascript (\"#{render :partial => 'share', :locals => { :user_location => ";
myHtml = myHtml.concat(index);
myHtml = myHtml.concat(".jpg }}");
$("#modal-test").append("<%= escape_javascript( myHtml ).html_safe %>");
});
</script>
This code will give me and error message:
undefined local variable or method `myHtml' for #< :0x007fe1d472cd70>
I tried to concat the whole string into myHtml and do an append(myHtml) but this way it will not render the erb code in the page. It shows as a string.
We have a carousel displaying images and the ultimate goal is when the user clicks on one of the images, we show a modal window with the image they clicked in there.
Any ideas?
Aucun commentaire:
Enregistrer un commentaire