I am trying to setup a form that takes in some song information. Right now the song title and the song artist.
Here is some of my code so far.
Song Model *EDIT
class Song < ActiveRecord::Base
has_one :song_artist_map
has_one :artist, :through => :song_artist_map
accepts_nested_attributes_for :artist
end
Artist Model
class Artist < ActiveRecord::Base
has_many :song_artist_maps
has_many :songs, :through => :song_artist_maps
end
SongArtistMap Model
class SongArtistMap < ActiveRecord::Base
belongs_to :song
belongs_to :artist
end
Songs Controller
def new
@song = Song.new
@song.artist.build
end
And inside my form I added this code
<% f.fields_for :artist do |a| %>
<li><%= a.label :name %></li>
<li><%= a.text_field :name %></li>
<% end %>
Right now nothing shows up in my form for artists.
So I need a way to be able to add an Artist from the form when a song is add and then make the mapping or just make the mapping if the artist already exists in my database.
I know I'm doing something very wrong here, can anyone please help? Thanks!