3

几周前我刚刚开始使用 ruby​​ on rails,我目前正在使用 rails composer(它使用 twitter-bootstrap-rails gem)构建一个博客。我想将引导轮播添加到我的应用程序视图(即我的 application.html.erb)

我已经尝试从 twitter bootstrap 文档中添加经典的 html 代码,但我只是得到了没有显示图片的左右控制器按钮。

有人有我的解决方案吗?

PS:我目前使用 Sass 进行引导设计。

编辑 02-11-2013 => 这是我的代码希望你能找到我的错误

<div class="container">
    <!--  Carousel -->
  <!--  consult Bootstrap docs at
        http://twitter.github.com/bootstrap/javascript.html#carousel -->
  <div id="this-carousel-id" class="carousel slide">
    <div class="carousel-inner">
      <div class="active item">
          <a><img src="assets/images/1.jpg" alt="Antennae Galaxies" /></a>

        <div class="carousel-caption">
          <p>The Antennae Galaxies</p>
          <p><a href="http://hubblesite.org/gallery/album/entire/pr2006046a/xlarge_web/npp/128/">Hubblesite.org &raquo;</a></p>
        </div>
      </div>
      <div class="item">
          <a><img src="assets/images/2.jpg" alt="Carina Caterpillar" /></a>

        <div class="carousel-caption">
          <p>Carina Nebula: The Caterpillar</p>
          <p><a href="http://hubblesite.org/gallery/album/entire/pr2007016e/xlarge_web/npp/128/">Hubblesite.org &raquo;</a></p>
        </div>
      </div>

    </div><!-- .carousel-inner -->
    <!--  next and previous controls here
          href values must reference the id for this carousel -->
      <a class="carousel-control left" href="#this-carousel-id" data-slide="prev">&lsaquo;</a>
      <a class="carousel-control right" href="#this-carousel-id" data-slide="next">&rsaquo;</a>
  </div><!-- .carousel -->
  <!-- end carousel -->
    <div class="content">
       <div class="row">
        <div class="span12">
          <%= render 'layouts/messages' %>
          <%= yield %>
        </div>
      </div>
      <footer>
      </footer>
    </div>
  </div> <!--! end of .container -->
</div> <!--! end of #main -->

<script>
$(function(){
$('#this-carousel-id').carousel();
});
</script>

</body>
</html>

编辑 2:这就是它在 Chrome 上的样子:http: //s7.postimage.org/kvp5cq4tn/Capture_d_cran_11_02_13_18_46_2.png

4

3 回答 3

3

代替

img src="assets/images/1.jpg" alt="Antennae Galaxies", 

为导轨使用以下图像标签:

link_to image_tag("1.jpg", :alt => "Slide1"), {:class => "img-responsive", :alt => "Responsive image"} 

并且不需要指定“assets/images”来显示图像文件夹。就够了1.jpg

于 2014-04-19T18:48:09.677 回答
1

您的 app/assets/javascripts/application.js 是否包含对引导程序的引用?

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .

我的轮播作为参考:

                <div class="span8 welcome-image">


                        <div id="myCarousel"
                        class="carousel slide">
                        <!-- Carousel items -->
                        <div class="carousel-inner">
                                <div class="active item">
                                        <a href="/users/sign_up"><img src="/pictures/1.png"> </a>
                                </div>
                                <div class="item">
                                        <a href="/users/sign_up"><img src="/pictures/2.png"> </a>
                                </div>
                                <div class="item">
                                        <a href="/users/sign_up"><img src="/pictures/3.png"> </a>
                                </div>
                                <div class="item">
                                        <a href="/users/sign_up"><img src="/pictures/4.png"> </a>
                                </div>
                                <div class="item">
                                        <a href="/users/sign_up"><img src="/pictures/WordcloudInsight.png"> </a>
                                </div>
                        </div>
                        <!-- Carousel nav -->
                        <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
                        <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
                </div>
于 2013-02-11T11:15:03.777 回答
0

Rails 中的 Bootstrap Carousel 突然停止工作

检查上面的链接,你也添加了这个+是jquery加载

<script>
$(function(){
  $('#myCarousel').carousel();
});
</script>
于 2013-02-11T01:04:31.727 回答