Bass-music issue


#1

hello guys, In the bass-music project, album list is being displayed twice on the page and I wasn’t able to find the error. I hope somebody knows the solution

here’s my code:

#albums.controller:

class AlbumsController < ApplicationController
  def index
  @albums = Album.all
end

def show
  @album = Album.find(params[:id])
  @tracks = @album.tracks
end
end
<!-- show.html -->

<div class="show row">
  <div class="cover col-md-4"><img src="<%= @album.cover %>"></div>

  <div class="col-sm-8">
    <h3 class="album-title"><%= @album.title %></h3>
    <p class="album-artist"><%= @album.artist %></p>

    <!--
     Loop through each track and display each one with this HTML
  -->

<% @tracks.each do |track| %>
    <div class="track row">
      <div class="name col-md-8"><%= track.name %></div>
      <div class="minutes col-md-4"><%= track.minutes %>min</div>
    </div>
<% end %>

  </div>
</div>
<!-- index.html -->

<div class="row">
  <% @albums.each do |album| %>
<div class="col-md-3">
     <%= link_to(album) do %>
    <div class="thumbnail">
      <img src="<%= album.cover %>">
      <div class="caption">
        <h3 class="title"><%= album.title %></h3>
        <p class="artist"><%= album.artist %></p>
      </div>
    </div>
    <% end %>
  </div>
  <% end %>
</div>
#routes.rb:

Rails.application.routes.draw do
  resources :albums
  root 'albums#index'
  get 'albums' => 'albums#show'
  
end

#2

Link please. Much simpler to debug if we can read the instructions and test your code.


#3

Hi mtf ,

here’s link to CC instructions:
https://www.codecademy.com/courses/learn-rails/projects/learn-rails_bass-music

and to the code:


#4

@anya.ruby Which URL shows the album list twice?

You should remove this line from your routes.rb file, since resources :albums already gives it a show route:

get 'albums' => 'albums#show'

The rest of your code looks alright. Would you mind posting the entire file contents for whichever page has the problem?


#5

Hi zystvan, thank you for checking it, I removed this line of code but the content is still somehow appearing twice on the page, it looks like this :

I created the app locally, so the entire code can be found under the link [–https://github.com/rubyruby1/bass-music]


#6

Running your code on my machine only shows each album once, making me think they may have gotten duplicated in the database, probably by you running rails db:seed twice. Try deleting the database, then creating a new one and bringing the data back in by running these commands in the terminal:

$ rails db:drop
$ rails db:create
$ rails db:migrate
$ rails db:seed 

(make sure you’re in the right directory when you run them)


#7

@zystvan, you were right, it helped! I had some issues with running the command rails db: drop (couldn’t be executed due to some permission issues) but rake db: setup solved it for me. Thank you a lot!!! Appreciate your help!


#8

This topic is solved.