samedi 22 août 2015

How not to display duplicates on ruby on rails 4?

I'm building an app that lets user upload videos from youtube, but users upload from the same artist multiple times but different songs. I need it to show only one song from the artist. right now this are the results im getting. "Sensato" is being put in 2 diffent groups even though is the same name of the artist.

Group El mayor - debarata

Group El Alfa - jevi

Group Future - where ya at

Group Sensato - Se Feliz

Group Sensato - Bello

(Controller)

def index
    @items = Video.all.order("cached_votes_up DESC, artist ASC")
    @items_by_day = @items.group_by { |t| t.artist }

end

(view)

    <% @items_by_day.each do |day, items| %>

            <div class="row">
            <h1>Group</h1>

            <% for a in items %>
            <div class="videothumb col-xs-12 col-sm-4">
                <div class="" style="
    background-size: 100% 100%;
    height: 240px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    overflow: hidden;">

                    <%= link_to  a do %>
  <div style="background: rgba(0,0,0, 0); width:100%; height: 85%;z-index:1000; position:absolute; top:0;"></div> 
<% end %>
                    <iframe width="100%" height="100%" src="https://www.youtube.com/embed/<%= a.url %>" frameborder="0" allowfullscreen></iframe>

                    </div>
                <div class="col-xs-12">
                <h3>
                    <%= link_to a.title, a %> </h3>
                </div>
                <div class="col-xs-6">
                <h2><%= a.artist %></h2>

                </div>
                <div class="col-xs-6">

                    <div style="text-align:right">
                        <%= link_to like_video_path(a), method: :put, class: "" do %>
                            <span class="glyphicon glyphicon-chevron-up">
                                <%= a.get_upvotes.size %>
                        <% end %> 
                        <%= link_to dislike_video_path(a), method: :put, class: "" do %>
        <span class="glyphicon glyphicon-chevron-down">
        <%= a.get_downvotes.size %>
      <% end %>

                    </div>
                </div>



            </div>
            <% end %>

            </div>


<% end %>

Final Result should look like this

Group El mayor - debarata

Group El Alfa - jevi

Group Future - where ya at

Group Sensato - Se Feliz

Aucun commentaire:

Enregistrer un commentaire