Adding dynamic bootstrap carousel Ruby on Rails 4 - ruby

Hello I have seen similar questions been asked but could not find a tutorial on how to create a dynamic bootstrap carousel in ruby on rails. The admin of my site needs to be able to browse and upload images rather than having to change any code. I have tried a carrier wave approach but was unable to get it working.
Here is my current carousel which is hard coded.
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<!-- Slide One - Set the background image for this slide in the line below -->
<div class="carousel-item active" style="background-image: url('assets/banner2.jpg')">
<div class="carousel-caption d-none d-md-block">
</div>
</div>
<!-- Slide Two - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-image: url('assets/Banner3.png')">
<div class="carousel-caption d-none d-md-block">
</div>
</div>
<!-- Slide Three - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-image: url('assets/SaleHero1.jpg')">
<div class="carousel-caption d-none d-md-block">
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Obviously at the moment if you want to change the images to something else it has to be done through the code. Could some point me in the right direction to get this task completed. Thank you :)

Assuming you can figure out how to upload images using carrier wave, you'll need to use ERB in your views.
<% #images.each do |image| %>
<div class="carousel-item" style="background-image: <%= images.url %>)">
<div class="carousel-caption d-none d-md-block">
</div>
</div>
<% end %>
You'll need to create a mode like image.rb which would need to store the images uploaded URL assuming you'll use an AWS S3 bucket. Then you'll need your code to store the url of the images in an attribute like url
Then in your controller you'll need something like:
def index
#images = Image.all.limit(10) # or however many images you wanna use
end

Related

Kentico 11: using variables inside text/xml transformations

I'm working on a carousel webpart with a text/xml transformation.
Simply trying to create a unique ID for each instance on the page.
Next I'd like to have the first item set to active with a CSS class.
For the section Webpart container:
{% uniqueId = string.FormatString("carousel-{0}", InstanceGuid.Substring(0,5)); #%}
<div id="{%uniqueId%}" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
□
</div>
<a class="carousel-control-prev" href="#{%uniqueId%}" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#{%uniqueId%}" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
This seems to work at first but for some reason it generates a text-node in HTML.
How can we do this without generating the variable output?
For a single carousel item in the Transformations section:
{% CssActive = IsFirst() ? "active" : string.Empty %}
<div class="carousel-item {%CssActive%}">
<img src="{%Image%}" alt="" class="w-100 d-block" />
<div class="carousel-caption d-none d-md-block">
<h3>{%Title%}</h3>
<div>{%Body%}</div>
</div>
</div>
This doesn't output anything? Is this even possible to use IsFirst() in a repeater?
Any help is much appreciated!
For the transformation you can use the following code:
<div class="carousel-item{% if (DataItemIndex == 0) { " active" } #%}">
<div class="card">
<img src="{%Image%}" alt="" class="card-img-top" />
<div class="card-body">
<h3 class="card-title">{%Title%}</h3>
<div class="card-text">{%Body%}</div>
</div>
</div>
</div>
Doc
For the Webpart container I can do a workaround with HTML/CSS:
<div class="d-none">
{% uniqueId = string.FormatString("carousel-{0}", InstanceGuid.Substring(0,5)); #%}
</div>
Far from ideal so if anybody else has a better idea ...?

Can I use lightbox2 in a <img> tag?

I'm new so I hope you can bare with me and help a newbie out.
I'm trying to apply the lightbox2 in a carousel. I want to be able to click on an image in my carousel and have that popping up in large in a lightbox. I followed all the steps (https://lokeshdhakar.com/projects/lightbox2/) but to apply the lightbox, it gives the example of using it in a a tag, but my images are inside a img tag.
I don't understand how I'm going to make it work, I've tried for hours now and I'm starting to give up. I think I'm confusing myself more than necessary.. Heres my carousel code:
<section class="page-section" id="portfolio">
<div class="container-fluid px-0">
<div class="row no-gutters">
<div class="col-md-8">
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="assets/img/portfolio/display-bw.jpg" alt="First slide"></div>
<div class="carousel-item">
<img class="d-block w-100" src="assets/img/portfolio/display-bw.jpg" alt="Second slide"></div>
<div class="carousel-item">
<img class="d-block w-100" src="assets/img/portfolio/display-bw.jpg" alt="Third slide"></div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
Thanks for your help,
Cris
I was able to get a kinda hacky solution.
You could do it like this. Replace "Image" in quotations with your image, and replace "data-lightbox" in quotations with what you want
<img id="minecraft" src="Image">
I don't think this is a good way but it works perfectly on my site. Also, I don't know if it will work on a carousel because I am also new but you can try.

image and data is not showing adjacent in bootstrap3

I am trying to image and its relevant data in bootstrap. For that I am writing code like below
<div class="col-xs-12 col-sm-3 col-sm-push-9">
<p style="padding:20px;"></p>
<h3 align=center>Our Lipsmacking Culinary Creations</h3>
</div>
<div class="col-xs-12 col-sm-9 col-sm-pull-3">
<div class="media">
<div class="media-left media-middle">
<a href="#">
<img class="media-object img-thumbnail" src="img/uthappizza.png" alt="Uthappiza">
</a>
<div class="media-body">
<h2 class="media-heading">Uthappizza</h2>
<p>A unique combination of Indian Uthappam (pancake) and
Italian pizza, topped with Cerignola olives, ripe vine
cherry tomatoes, Vidalia onion, Guntur chillies and
Buffalo Paneer.</p>
<p><a class="btn btn-primary btn-xs" href="#">More »</a></p>
</div>
</div>
</div>
</div>
I am getting output like this:
enter image description here
I want it to be side by side I don't know where I am going wrong.
Add pull-left to your image as a class. Bootply.

Element div not allowed as child of element ul in this context

this is my first post
just the site i needed cause im kinda new to all this
im trying to validate my page and there is 1 error that i dont know what to do with
Element div not allowed as child of element ul in this context. (Suppressing further errors from this subtree.)
if i remove the div part
my page is not looking the same as it does with it and it works on all browsers right now with the errors
this is the piece of code that is making the error
<div class="picture_content margin-left">
<ul class="image_box_story2">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="images/slider1.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="images/slider2.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="images/slider3.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
</div>
</div>
</ul>
</div>
</div>
</section>
any help on how to fix this would be apreciated alot
thanks for taking the time
btw i downloaded a bootstrap temp and the Original file has the same errors
The error is
<ul class="image_box_story2">
a ul is a list and can only have li children, not div, that list doesn't have any li children at all.
Perhaps you can change it to <div class="image_box_story2"> (and change (</ul> to </div>) that would make it valid, but whether it displays Ok depends on the css you have not shown.

Bootstrap 3 carousel not working on Magento

Can't get this carousel to work on a Magento site. I have one image displaying ok, just the transition between images not happening.
Example that im working on here - http://dev.clothesforsale.co.nz/
Code below:
<div id="myCarousel" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);?>slider/example-banner-one.jpg" alt="Slider One" class="img-responsive"/>
</div>
</div>
<div class="carousel-inner">
<div class="item">
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);?>slider/example-banner-two.jpg" alt="Slider Two" class="img-responsive"/>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<script type="text/javascript">
// <![CDATA[
$(function(){
$('.carousel').carousel();
});
// ]]>
</script>
At first glance, the console shows Object #<Object> has no method 'on' when the page loads, originating on line 163 of bootstrap.js. If I jQuery.fn.jquery in the console to get the jQuery version, it says 1.4.2.
This answer suggests that the on method (which Bootstrap appears to be using) wasn't added until jQuery 1.7. An upgrade might be the first step.

Resources