Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在我的图像索引页面上启用jquery_Ruby On Rails - Fatal编程技术网

Ruby on rails 在我的图像索引页面上启用jquery

Ruby on rails 在我的图像索引页面上启用jquery,ruby-on-rails,Ruby On Rails,我有从我的图像中提取的代码,并将每个代码包含在一个div中,其中包含一个唯一的id和一个统一的class <% @albums.at(3)["photos"]["data"].each do |data| %> <div id="<%= data["id"] %>" class="myImages" data-toggle="modal" data-target="#myModal"> <%= image_tag data

我有从我的图像中提取的代码,并将每个代码包含在一个div中,其中包含一个唯一的
id
和一个统一的
class

<% @albums.at(3)["photos"]["data"].each do |data| %>
    <div id="<%= data["id"] %>" class="myImages" data-toggle="modal" data-target="#myModal">
            <%= image_tag data["images"].first["source"] %>
    </div>
<% end %>
现在,我想通过点击这些图片中的一个来替换模态的内容,就像这样

我一直在这样使用jquery:

查看/images/select.js.erb

$(".myImages").click(function (e){
    e.preventDefault();
    $(".modal-body").html($(this).html());
  });
});
<script>
  //the same jquery code
</script>
我不明白的是,当我将此jquery代码添加到
select.js.erb
时,该函数在我的图像索引页面上不起作用。我留下了一个“…”的模态体,没有被图像替换

但是当我将其添加到我的index.html.erb

$(".myImages").click(function (e){
    e.preventDefault();
    $(".modal-body").html($(this).html());
  });
});
<script>
  //the same jquery code
</script>

//相同的jquery代码
它的工作原理和我需要的完全一样

我希望将所有jquery放在不同的文件中。我是否遗漏了一些特定于rails的东西,这些东西不允许我像我解释的那样重构jquery(我认为这是正确的词)