rails 4 justifiedGallery 脚本只加载最新的 post 图像

rails 4 justifiedGallery script only load the latest post with images

当我用图像创建一个新的 post 时它可以工作,但是当我用图像创建一个新的 post 时,justifiedGallery 不会将 jquery 脚本应用到之前的 post,为什么?

jQuery -> //when dom is ready
  $("#userindex").justifiedGallery(
    lastRow : 'justify',
    captions: false,
    randomize: false,
    rowHeight: 80,
  )

查看渲染 post 图像

<div id="userindex">
   <% img.each do |link| %>
      <div>
          <%= image_tag(link) %>
      </div>
   <% end %>                 
</div>  

如果您想了解为什么会发生这种情况,请阅读

将您的脚本更改为:

jQuery -> //when dom is ready
  $(".my-class").justifiedGallery(
    lastRow : 'justify',
    captions: false,
    randomize: false,
    rowHeight: 80,
  )

您的 html 代码为:

<div id="userindex" class="my-class">
   <% img.each do |link| %>
      <div>
          <%= image_tag(link) %>
      </div>
   <% end %>                 
</div>