I'm trying to add a users username to a song.
app/models/user.rb
class User < ActiveRecord::Base
has_many :songs
...
end
app/models/song.rb
class Song < ActiveRecord::Base
belongs_to :user
...
end
I'm trying to make a migration to add a username table to my songs table
class AddUsernameToSongs < ActiveRecord::Migration
def change
add_column :songs, :username, :string
end
end
But I keep getting an uninitialized constant error when I try to run rake db:migrate
I want to be able to on each song call
<%= song.username %>
To post the author of the track.
I'm using devise to set up my users and the devise table already has a username field.
song.usernameisn't magic. You need to be sure you assign a value to that attribute.song.user.username