I'm having trouble understanding how to pass in a variable to modal, so that I can use (not as an input in a form) but to use in a helper method.
I've looked at: Passing data to a bootstrap modal and How to pass values arguments to modal.show() function in Bootstrap and Bootstrap JavaScript
Link_to modal:
<%= link_to "#{comment.fname}", "#commenterModal", :class => "btn commenter", "data-toggle" => "modal", "data-id" => "4"%> I'm using data-id="4" to test, but I would be passing in Rails variable comment.id.
Modal:
<div id="commenterModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-body" style="background-color: #F5F5F5;"> <div class="row" id="commentId"> <%= getuserprofileofcommenter(commentId).bio %> </div> <div class="modal-footer"> <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">OK</button> </div> </div> </div> </div> </div> JS:
$(document).ready(function() { $('#commenterModal').on('show.bs.modal', function(event) { $("#commentId").val($(event.relatedTarget).data('id')); }); }); I know I'm not understanding this correctly. But I'm trying to take this instance when I click on the link_to, pass the variable (comment.id) in to the modal so I can use it when I call the helper method "getuserprofileofcommenter(commentId)".
Any insight would help. Thank you!