SuBzer0
SuBzer0

Reputation: 45

Image Gallery in Rails

I have a multiple upload images, using carrier wave, on my application and with the help of you guys, in another question, I was able to display all the images with a each method. It works very well but I would like to improve it. I want to do a image gallery with a carousel and when the user click at it opens a modal with the image bigger.
I try to do following the tutorial of W3C School but just doesn't work. When I try to put the Onclick method the page doesn't render.

https://www.w3schools.com/howto/howto_js_lightbox.asp

There is any gem that help me do this? There is any tutorial for a rails application?
I am displaying the images with the following code:

<% @imovel.imagens.each do |imagem| %>
          <div class="col-sm-6 col-md-4">
            <div class="thumbnail">
              <%= image_tag(imagem.url) if @imovel.imagens? %>
          </div>
        </div>
<% end %>

Upvotes: 0

Views: 1516

Answers (1)

Thiago Ururay
Thiago Ururay

Reputation: 462

You will use link_to to create the a tag with a block. The arguments are:

link_to(url, html_options = {})

Inside the block, you will put the html code inside the a tag (your image).

<% @imovel.imagens.each do |imagem| %>
          <div class="col-sm-6 col-md-4">
            <div class="thumbnail">
              <%= link_to imagem.url, class: 'your-css-class', 'data-toggle': 'lightbox', 'data-gallery': 'name-of-gallery' do %>
                  <%= image_tag(imagem.url) %>
              <% end if @imovel.imagens? %>
          </div>
        </div>
<% end %>

Upvotes: 2

Related Questions