I have a bootstrap carousel on a page, where I have 3 game cards per one slide, but they are hardcoded. How can I make them dynamic? I need to take game cards from my db. This is what I have now:
<div id="carousel" class="carousel-inner thumb-inner">
<div class="active item">
<div class="col-lg-12 col-md-12 col-xs-12 slide1 slider-div">
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
</div>
</div>
<div class="item">
<div class="col-lg-12 col-md-12 col-xs-12 slide1 slider-div">
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
</div>
</div>
</div>
What is the right way to put a ruby code here? My thoughts were smth. like this:
<div class="active item">
<div class="col-lg-12 col-md-12 col-xs-12 slide1 slider-div">
<% Game.all.each_with_index do |game, index| %>
<div class="col-lg-4 col-md-4 col-sm-4">
<%= game.title %>
</div>
<% end %>
</div>
</div>
But this will give me all game card on a slide. What is the correct way to make 3 game card per one slide? Thanks.
You could make use of limit and offset here to get 3 records at a time. For example:
Game.offset(0).limit(3) # first 3 items
Game.offset(3).limit(3) # next 3 items
If the Game table only has a small number of records that fit comfortably in memory, you could also do something like this:
items = Game.all.to_a # do this once to load up all the records
items.shift(3) # call repeatedly to get the next 3 items
This has the advantage that you can randomise the items upfront e.g. Game.order("RANDOM()").to_a
Related
My images wont stay on the same row once i put the <p> in, they both sit in there own row, not sure what im doing wrong here
<div class="container">
<div class="row">
<div class="image-fluid text-center">
<img class="bruno" src="resourcesnew/css/Img/bruno.jpg">
<p class="h6">Bruno</p>
<img class="anth" src="resourcesnew/css/Img/anth.jpg">
<p class="h6">Anthony</p>
</div>
</div>
</div>
I think whatever CSS you used in class="row" is not acting the way you expect, because that div has a single child.
I don't know what's in your css file, but the following HTML works as I expect you want:
<div class="container">
<div class="image-fluid text-center" style="display:flex">
<div>
<img class="bruno" src="resourcesnew/css/Img/bruno.jpg">
<p class="h6">Bruno</p>
</div>
<div>
<img class="anth" src="resourcesnew/css/Img/anth.jpg">
<p class="h6">Anthony</p>
</div>
</div>
</div>
Each image/text pair gets its own div, and what used to be your row div now has multiple children.
I have two columns in a row: one column holding an album image, and the other column holding some text describing the album. Above the medium breakpoint, the columns and the content within them are aligned perfectly. But when the screen is sized below the medium breakpoint, the column holding the album image expands to the right.
Here is the code:
<div class="card mb-3">
<div class="card-header py-3">
<div class="row">
<div class="col-2 d-none d-md-block column image-col">
<img src="images/NirvanaNevermindalbumcover.jpg" class="rounded review-img" />
</div>
<div class="col-10 column text-col">
<div class="d-flex justify-content-between album-header">
<h5 class="card-title">Nirvana - Nevermind</h5>
<p>Avg. Rating: <span class="rating">8.6</span></p>
</div>
<div class="d-flex justify-content-between user-header">
<p class="text-muted">Reviewed by <a class="username" href="#">PunkyBruiser</a> on May 14, 2022</p>
<p class="text-muted">User Review: <span class="added-rating">8</span></p>
</div>
</div>
</div>
</div>
I've tried to use pe-sm-1 and other similar size measurements from Bootstrap5 on the <div class="col-2 ..."> but nothing has changed.
I've even tried putting a d-flex justify-content-start on the row but that didn't change anything either.
I am trying to get my cards to show-up as three in a row and then jump to the next line and put the next three. Right now, it's just putting each card right below the one above it. Can anyone help me out?
<div class="container">
<div class="row">
<div class="col-md-6">
<% #block_busters.each do |movie| %>
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="<%= movie.image_url %>" alt="Card image cap">
<div class="card-body">
<h4 class="card-title"><%=movie.title%></h4>
<p class="card-text"><%=movie.description%></p>
</div>
</div>
<%end%>
</div>
</div>
</div>
You're most likely looking for the 'slice' method, try something like this:
<% #block_busters.each_slice(3) do |slice| %>
<div class="row">
<% slice.each do |movie| %>
<div class="col-md-4"> <!-- 12 cols / 3 cards = 4 -->
<!-- render your cards here, each will show up in rows of 3 -->
</div>
<% end %>
</div>
<% end %>
Currently I am making a twitter clone using RubyOnRails and bootstrap as the framework. When trying to distribute some text in a post panel using the "col-sm" div class, the text seems jammed together on the left,
as seen here.
Here is my code:
<div class="row">
<div class="col-xs-3">
<div class="panel panel-default">
<div class="panel-body">
<p>status</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<p>trend</p>
</div>
</div>
</div>
<div class="col-xs-6">
<%= render '/components/post_form' %><br></br>
<% for #p in #posts %>
<div class="panel panel-default post-panel">
<div class="panel-body">
<div class="col-sm-1">
AVATAR
</div>
<div class="col-sm-11">
<p><%= #p.content %></p>
</div>
<div class="col-sm-12">
LINKS
</div>
</div>
</div>
<% end %>
</div>
<div class="col-xs-3">
<div class="panel panel-default">
<div class="panel-body">
<p>about</p>
</div>
</div>
</div>
</div>
I am using the latest bootstrap sass version 3.3.6 which is included in the gemfile. Is there something wrong with the code or does the latest version of bootstrap mean I need to do something different?
Look at this section:
<div class="col-sm-1">
AVATAR
</div>
<div class="col-sm-11">
<p><%= #p.content %></p>
</div>
<div class="col-sm-12">
LINKS
</div>
The first issue is the text "AVATAR" is wider than 1 bootstrap column, so it's extending out of your container. using col-sm-2/col-sm-10 may fix the issue.
Second, column sizes should add up to 12 columns per row. Here you have a col-sm-1, col-sm-11, and col-sm-12 all in the same row.
Hi please look at this,
<div class="row">
<div class="col-lg-5"></div>
<div class="col-lg-15">
<div class="row">
<div class="col-lg-**2/3**"></div>
<div class="col-lg-**1/3**"></div>
</div>
</div>
How Can I do it without separator?
I would like to do something like that:
<div class="row">
<div class="col-lg-10"></div>
<div class="col-lg-5"></div>
</div>
This is Grid - 20 columns, 5 column sidebar 15 rest.
Bootstrap is based on a 12 column grid. If you want a column to be 2/3's of a page with a sidebar 1/3 I would do the following.
<div class="container>
<div class="row">
<div class="col-sm-8">
<p> This content is 2/3 of the page</p>
</div><!-- col-sm-8 -->
<div class="col-sm-4 -->
<p>This content is 1/3 of the page</p>
</div><!-- col-sm-4 -->
</div><!-- row -->
</div><!-- container -->
If you are wanting it to be responsive I would start with defining the smaller screen size "col-sm-?" and large screens will inherit this.
Otherwise, I'm not sure what you are trying to achieve and what you mean by separator. Could you clarify?
Hope this helps.