bootstrap-gallery,激活gallery容器上的插件

时间:2014-10-09 21:32:55

标签: javascript ruby-on-rails twitter-bootstrap

我正在尝试在我的rails 4 app中使用bootstrap-gallery

我遵循简单的指示,不理解其含义:

3.  activate the plugin on the gallery container

$('.gallery').bootstrapGallery();

我试图将其添加到我的视图顶部:

<script>
$('.gallery').bootstrapGallery();
</script>

但是当我点击图像时,JS似乎没有执行(我刚刚被带到图像URL),我在JS控制台中遇到以下错误:

Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined
Uncaught TypeError: Cannot call method 'addMarker' of undefined

指示我出错的地方?

编辑:这就是我的观点:

<%= javascript_include_tag "bootstrap-gallery" %>
<%= stylesheet_link_tag "bootstrap-gallery" %>

<div class="gallery row">
  <% @post.assets.each do |asset| %>
     <a class="col-xs-6 col-sm-4" href=<%= asset.asset.url(:medium) %>>
       <img src=<%= asset.asset.url(:medium) %> alt="">
     </a>
  <% end %>
</div>

<script>
var ready;
ready = function() {
  $('.gallery').bootstrapGallery();
};

$(document).ready(ready);
$(document).on('page:load', ready);
</script>

仍然遇到同样的问题:

Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined

1 个答案:

答案 0 :(得分:0)

尝试:

$('.gallery').bootstrapGallery({});

出于某种原因,脚本期望将选项传递给它;如果您不需要更改任何内容,可以将选项设置为空。

相关问题