1

I am trying to implement the simple bootstrap carousel in my Rails application and use it as a simple tour of my site. It works with one major exception. There is no slide action. It simple changes from one item to the next. Here is my code:

<!DOCTYPE html>
  <html>
    <head>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title><%= full_title(yield(:title)) %></title>
      <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
      <%= csrf_meta_tags %>
  </head>
 <body>  


  <div id="TourCarousel" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#TourCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#TourCarousel" data-slide-to="1"></li>
      <li data-target="#TourCarousel" data-slide-to="2"></li>
    </ol>
      <div class="carousel-inner">
          <div class="item active">
            <img src="" alt="">
            <div class="carousel-caption">
            <h3>Caption Text 1</h3>
         </div>
     </div>
     <div class="item">
         <img src="" alt="">
         <div class="carousel-caption">
         <h3>Caption Text 2</h3>
    </div>
    </div>
    <div class="item">
         <img src="" alt="">
         <div class="carousel-caption">
         <h3>Caption Text 3</h3>
        </div>
      </div>
     </div>
          <a class="left carousel-control" href="#TourCarousel" role="button" data-slide="prev">
          <span class="glyphicon glyphicon-chevron-left"></span></a>
          <a class="right carousel-control" href="#TourCarousel" role="button" data-slide="next">
          <span class="glyphicon glyphicon-chevron-right"></span></a>
   </div>

   <script type="text/javascript">

      $(document).ready(function(){
        $('.carousel').carousel();
      });

   </script>
  </body>
 </html>

I cannot see why this is not sliding. Its basically cut and pasted from the bootstrap site.

I have seen many questions on this and most lead up to including the script to initiate the carousel:

Bootstrap carousel not sliding

...but I have followed this instruction with no impact on the functionality of the carousel. In addition previous questions haven't looked at this in Rails specifically (not that I can see why this would make a difference).

Community
  • 1
  • 1
GhostRider
  • 2,109
  • 7
  • 35
  • 53
  • Are you having any other issues with Bootstrap, specifically with components that rely on JS? I tested your code inside rails and it works without issue. – vanburen Sep 27 '15 at 15:51
  • my drop-downs, nav-bars and stateful submit buttons all work fine. I can't see anywhere where I have included jQuery files twice (I notice this was the problem for others sometimes). I'll test it in a new rails app. – GhostRider Sep 27 '15 at 16:42
  • Have you looked to see if you have any js errors flagged in the browser console? – Elvn Sep 27 '15 at 21:07
  • No errors of any kind in the console and all my other JS is working fine. In addition, the carousel is auto-changing every few seconds. Its just not sliding. argghh – GhostRider Sep 28 '15 at 14:50

0 Answers0