0
私はProduct
モデルを持っています。ビュー内のリンクをクリックすると、モーダルが特定のproduct
に関連するデータで表示されます。私は製品id
をdata-attribute
のリンクに保存しています。これは、AJAX機能を呼び出すRails + AJAX:ActiveRecordオブジェクトを使用してモーダルを読み込み
# They click the label containing the data-attribute
<% @products.each do |prod| %>
<%= f.label prod.name, data: {id: prod.id}, class: "product-info" %>
<% end %>
:
# Modal
<div class="modal" id="product-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title text-center"><strong>Nutrition Facts:</strong></h4>
</div>
<div class="modal-body"></div>
</div>
</div>
</div>
は、その後、私は、ユーザーがクリックしますリンクを持つ
$(".product-info").click(function() {
url = "/products/" + $(this).data("id")
$.get(url, function(data) {
console.log(data) # nothing shows here
}, 'script')
})
を...最終的に私は、次のと私のproducts/show.js
見解を持っています:
$(".modal-body").html(<%= escape_javascript(render :partial => '/food_orders/nutrition', :locals => {prod: @product}) %>)
$("#product-modal").fadeIn();
console.log("Is this working?"); # I never see this in the console
私の開発者ツールでは、ajaxリクエストへの応答にはshow.js
が含まれていますが、これはユーザーに表示されることはありません。
あなたは答えとしてそれをマークする必要があります。.. – uday