[Rails] Implementation of image slide show using Bootstrap 3

Target

ezgif.com-video-to-gif.gif

Development environment

・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina

Premise

The following has been implemented.

Slim introductionIntroduction of Bootstrap3Implementation of posting functionImplementation of multiple image upload function

Implementation

1. Edit the view

slim:books/show.html.slim


/Postscript
.row
  #sampleCarousel.carousel.slide data-ride='carousel'
    ol.carousel-indicators
      li.active data-target='#sampleCarousel' data-slide-to='0'
      li data-target='#sampleCarousel' data-slide-to='1'
      li data-target='#sampleCarousel' data-slide-to='2'
    .carousel-inner role='listbox'
      - @book.images.each.with_index(1) do |image, index|
        - if index == 1
          .item.active
            = image_tag image.to_s, class: 'img-responsive img-rounded carousel-image'
        - else
          .item
            = image_tag image.to_s, class: 'img-responsive img-rounded carousel-image'
    a.left.carousel-control href='#sampleCarousel' role='button' data-slide='prev'
      span.glyphicon.glyphicon-chevron-left aria-hidden='true'
      span.sr-only
        |Forward
    a.right.carousel-control href='#sampleCarousel' role='button' data-slide='next'
      span.glyphicon.glyphicon-chevron-right aria-hidden='true'
      span.sr-only
        |next

[Explanation]

(1) Repeat the process of the image list registered in the book and assign an index.

- @book.images.each.with_index(1) do |image, index|

(2) Set the image to be displayed on the first sheet.

This time, I'm setting an image with index 1.

- if index == 1
  .item.active
    = image_tag image.to_s, class: 'carousel-image'

③ Set the second and subsequent images.

- else
  .item
    = image_tag image.to_s, class: 'carousel-image'

2. Edit ʻapplication.scss`

application.scss


.carousel-image {
  width: 30%; //Set the width of the image for the slide
  margin: 0 auto; //Center image
}

Recommended Posts

[Rails] Implementation of image slide show using Bootstrap 3
[Rails] Implementation of image enlargement function using lightbox2
[Rails] Implementation of image preview function
[Ruby on Rails] Carousel of bootstrap4 is implemented as a slide show using each method.
[Rails] Implementation of search function using gem's ransack
[Rails] Implementation of PV number ranking using impressionist
[Rails] Implementation of multi-layer category function using ancestry "Preparation"
[Rails] Implementation of multi-layer category function using ancestry "seed"
Implementation of image preview function
[Rails] Implementation of category function
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
[Rails] Implementation of multi-layer category function using ancestry "Editing form"
[Rails] Implementation of automatic address input using jpostal and jp_prefecture
[Rails] Implementation of multi-layer category function using ancestry "Creation form"
[Rails] Implementation of user logic deletion
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
[Rails] About implementation of like function
[Rails] Implementation of CSV export function
Implementation of validation using regular expressions
[Rails] Implementation of many-to-many category functions
[Rails] Implementation of new registration function in wizard format using devise
[Rails] Implementation of coupon function (with automatic deletion function using batch processing)
[Rails] Implementation of tag function using acts-as-taggable-on and tag input completion function using tag-it
[Rails] Implementation of multi-layer category function using ancestry "I tried to make a window with Bootstrap 3"
Implementation of user authentication function using devise (2)
[Rails] I will explain the implementation procedure of the follow function using form_with.
Implementation of user authentication function using devise (1)
[Ruby on Rails] Image slideshow using Skippr
Rails [For beginners] Implementation of comment function
Implementation of tabs using TabLayout and ViewPager
Implementation of user authentication function using devise (3)
How to implement image posting using rails
[Ruby on rails] Implementation of like function
[Rails] Implementation of validation that maintains uniqueness
Implementation of Ruby on Rails login function (Session)
[FCM] Implementation of message transmission using FCM + Spring boot
[Rails] Display of multi-layered data using select boxes
[Nuxt / Rails] POST implementation using axios and devise_token_auth
Try similar search of Image Search using Java SDK [Search]
[Rails] Implementation of "notify notification in some way"
[Rails] Show avatars in posts using Active Storage
Implementation of Google Sign-In using Google OAuth 2.0 authentication (server edition)
[Rails] Implementation of drag and drop function (with effect)
Implementation of Ruby on Rails login function (devise edition)
[Rails] When using ajax, be aware of "CSRF measures".
Using PAY.JP API with Rails ~ Implementation Preparation ~ (payjp.js v2)
Rails6: Input the initial data of ActionText using seed
Try using the query attribute of Ruby on Rails
Explanation of Ruby on rails for beginners ⑦ ~ Flash implementation ~