17. bass-music


#1

I get a "Couldn't find Track without an ID" error. Here is my code, where am I going wrong?

Albums controller:

class AlbumsController < ApplicationController
  def index
    @albums = Album.all
  end
  def show
    @album = Album.find(params[:id])
    @tracks = Track.find(params[:album_id])
  end
end

tracks migration

class CreateTracks < ActiveRecord::Migration
  def change
    create_table :tracks do |t|
			t.string :name
      t.string :minutes
      t.references :album
      t.timestamps
    end
  end
end

show view

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

  <div class="col-sm-8">
    <h3 class="album-title"> <%= @album.title %> </h3>
    <p class="album-artist"> <%= @album.artist %> </p>   
    
<%= @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>

#2

Hi @megarunner02201,

@tracks = Track.find(params[:album_id])

There is no album_id parameter in the URL. Looking at the line above, we see it's just the id parameter. Try using that instead :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.


Step 17 undefined method