【Rails】Bootstrap3를 이용한 이미지 슬라이드 쇼 구현
목표
 
 개발 환경
· Ruby : 2.5.7
·Rails: 5.2.4
·Vagrant: 2.2.7
· VirtualBox : 6.1
· OS : macOS Catalina
 전제
하기 실장 완료.
· Slim 도입
· Bootstrap3 도입
· 게시 기능 구현
· 이미지 다중 업로드 기능 구현
 구현
 1. 뷰 편집
books/show.html.slim/ 追記
.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
        | 前へ
    a.right.carousel-control href='#sampleCarousel' role='button' data-slide='next'
      span.glyphicon.glyphicon-chevron-right aria-hidden='true'
      span.sr-only
        | 次へ
 【해설】
 ① 책에 등록되어 있는 화상 일람을 반복 처리해, index를 부여한다.
- @book.images.each.with_index(1) do |image, index|
 ② 1장째에 표시하는 화상을 설정한다.
이번에는 index가 1인 이미지를 설정하고 있습니다.
- if index == 1
  .item.active
    = image_tag image.to_s, class: 'carousel-image'
 ③ 2매째 이후의 화상을 설정한다.
- else
  .item
    = image_tag image.to_s, class: 'carousel-image'
 2. application.scss 편집
application.scss.carousel-image {
  width: 30%; // スライドに対する画像の幅を設定
  margin: 0 auto; // 画像を中央に配置
}
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(【Rails】Bootstrap3를 이용한 이미지 슬라이드 쇼 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/matsubishi5/items/c7c8ea1abb35aa98f48d
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
· Ruby : 2.5.7
·Rails: 5.2.4
·Vagrant: 2.2.7
· VirtualBox : 6.1
· OS : macOS Catalina
전제
하기 실장 완료.
· Slim 도입
· Bootstrap3 도입
· 게시 기능 구현
· 이미지 다중 업로드 기능 구현
 구현
 1. 뷰 편집
books/show.html.slim/ 追記
.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
        | 前へ
    a.right.carousel-control href='#sampleCarousel' role='button' data-slide='next'
      span.glyphicon.glyphicon-chevron-right aria-hidden='true'
      span.sr-only
        | 次へ
 【해설】
 ① 책에 등록되어 있는 화상 일람을 반복 처리해, index를 부여한다.
- @book.images.each.with_index(1) do |image, index|
 ② 1장째에 표시하는 화상을 설정한다.
이번에는 index가 1인 이미지를 설정하고 있습니다.
- if index == 1
  .item.active
    = image_tag image.to_s, class: 'carousel-image'
 ③ 2매째 이후의 화상을 설정한다.
- else
  .item
    = image_tag image.to_s, class: 'carousel-image'
 2. application.scss 편집
application.scss.carousel-image {
  width: 30%; // スライドに対する画像の幅を設定
  margin: 0 auto; // 画像を中央に配置
}
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(【Rails】Bootstrap3를 이용한 이미지 슬라이드 쇼 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/matsubishi5/items/c7c8ea1abb35aa98f48d
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
1. 뷰 편집
books/show.html.slim
/ 追記
.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
        | 前へ
    a.right.carousel-control href='#sampleCarousel' role='button' data-slide='next'
      span.glyphicon.glyphicon-chevron-right aria-hidden='true'
      span.sr-only
        | 次へ
【해설】
① 책에 등록되어 있는 화상 일람을 반복 처리해, index를 부여한다.
- @book.images.each.with_index(1) do |image, index|
② 1장째에 표시하는 화상을 설정한다.
이번에는 index가
1인 이미지를 설정하고 있습니다.- if index == 1
  .item.active
    = image_tag image.to_s, class: 'carousel-image'
③ 2매째 이후의 화상을 설정한다.
- else
  .item
    = image_tag image.to_s, class: 'carousel-image'
2. application.scss 편집
application.scss
.carousel-image {
  width: 30%; // スライドに対する画像の幅を設定
  margin: 0 auto; // 画像を中央に配置
}
Reference
이 문제에 관하여(【Rails】Bootstrap3를 이용한 이미지 슬라이드 쇼 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/matsubishi5/items/c7c8ea1abb35aa98f48d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)