<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hai Ho on Medium]]></title>
        <description><![CDATA[Stories by Hai Ho on Medium]]></description>
        <link>https://medium.com/@hohoanghai14894?source=rss-7e5933662fc0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UlX8dKgRrdvVVUC3</url>
            <title>Stories by Hai Ho on Medium</title>
            <link>https://medium.com/@hohoanghai14894?source=rss-7e5933662fc0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:26:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hohoanghai14894/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create a slideshow by looping through  uploaded user’s pictures with carousel in your Ruby…]]></title>
            <link>https://medium.com/@hohoanghai14894/how-to-create-a-slideshow-by-looping-through-uploaded-users-pictures-with-carousel-in-your-ruby-28f4ce685322?source=rss-7e5933662fc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/28f4ce685322</guid>
            <category><![CDATA[bootstrap]]></category>
            <category><![CDATA[carousel]]></category>
            <category><![CDATA[slideshow]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Hai Ho]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 12:56:40 GMT</pubDate>
            <atom:updated>2020-06-01T12:56:40.264Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to create a slideshow by looping through uploaded user’s pictures with carousel in your Ruby on Rails app using bootstrap.</h3><p>Hi everyone, i’ve recently finish my first rails project and when i was building my app, i wanted to loop through the pictures that user has uploaded and make a carousel button where you can click and back and forth for different picture as below. Since i’m only new to programming and haven’t touched on JavaScript, this this the best solution i came up with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7crmBwKFKRTnoag9jDiAXg.png" /></figure><h3><strong>1. How to upload multiple pictures.</strong></h3><p>So assuming you’re familiar the Rails and know to make a form and a button to upload picture, i’m not going to cover that. Let’s say you have a listing model, in the listing you want to upload multiple pictures to it, you have to go to Listing model (listing.rb file) and add has_many_attached :picture to the model. Now in most rails app you need Action Controller Parameters, basically a list of trusted parameters that allow through, you need to add to add the picture parameter, which is an array of picture to it:</p><p>params.require(:listing).permit(:picture [])</p><h3>2. How to show only one picture.</h3><p>So now that your you have an array of pictures, any time you want to use only it, you have to specify what picture you want to use in the array. For example if you have an image_tag and you want to use the first picture in the array, which is at index 0, you have to put</p><p>&lt;%= image_tag listing.picture[0]%&gt;</p><h3>3. How to make a slideshow of pictures with carousel.</h3><p>First off make sure you have Bootstrap up and running. All the code of how to to make a carousel is available <a href="https://getbootstrap.com/docs/4.3/components/carousel/"><strong><em>here</em></strong></a><strong><em> </em></strong>in the Bootstrap documentation. I’m going to talk about the most important &lt;div&gt; element here which is carousel-inner , and inside it will contain carousel-item .</p><p>The most important part with this carousel is with a bunch of images, we have to give one and only one picture (here is carousel item) an active class (often the first picture in the array since we can have one or multiple pictures), which is the first picture that is being shown by default. Without the active it is not gonna work. The question is how do we give just first item the active class when we loop through the images?</p><p>We have to write a function where we only give the class active to the first item, which is at the 0 index.</p><pre>&lt;div class=”carousel-inner”&gt;<br>  &lt;%@listing.picture.each_with_index <em>do</em> |pic,i|%&gt;<br>  &lt;div class=&quot;carousel-item &lt;%= &quot;active &quot; <em>if</em> i==0 %&gt;&quot;&gt;<br>       &lt;%= image_tag  pic %&gt;<br>  &lt;/div&gt;<br>  &lt;%<em>end</em>%&gt;<br>&lt;/div&gt;</pre><h3>4. How to change the colour of the carousel control icon.</h3><p>The default of the carousel control arrow is white, and if you have a white or light background , you won’t be able to see it. So how to change it since Bootstrap carousel in the background written by javascript and you have no idea how to modify it? You just need to add these line of code below to your application.scss file.</p><pre>.carousel-control-next-icon {<br>background-image: url(https://medium.com/&quot;data:image/svg+xml;charset=utf8,%3Csvg%20xmlns=&#39;http://www.w3.org/2000/svg&#39;%20fill=&#39;black&#39;%20viewBox=&#39;0%200%208%208&#39;%3E%3Cpath%20d=&#39;M2.75%200l-1.5%201.5%202.5%202.5-2.5%202.5%201.5%201.5%204-4-4-4z&#39;/%3E%3C/svg%3E&quot;);<br>}</pre><pre>.carousel-control-prev-icon {<br>background-image: url(https://medium.com/&quot;data:image/svg+xml;charset=utf8,%3Csvg%20xmlns=&#39;http://www.w3.org/2000/svg&#39;%20fill=&#39;black&#39;%20viewBox=&#39;0%200%208%208&#39;%3E%3Cpath%20d=&#39;M5.25%200l-4%204%204%204%201.5-1.5-2.5-2.5%202.5-2.5-1.5-1.5z&#39;/%3E%3C/svg%3E&quot;);<br>}</pre><p>You can change the colour of the carousel by changing the fill field.</p><p>And Voila, there you have it. Good luck and have fun coding.!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28f4ce685322" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>