Topic: Forms for has_many :through associations

I'm fairly new to Rails, so any help would be greatly appreciated.

My app has two models, Song and Color, which are linked through the SongColor relationship. A song has many colors through song_color.

On the show page for Song, I want to include a form that will create a new color with the given parameters (RGB values), and link that to the song using song_color. So both a color and a song_color will be created by the form.

I'm not sure on how exactly to do this. Would using a nested form be the way to go?

Re: Forms for has_many :through associations

This is what I have right now on the show page for song

<%= form_for [@song, @song_color] do |f| %> // this line is definitely wrong
        <%= f.hidden_field :red, :id => 'redValue' %>
        <%= f.hidden_field :green, :id => 'greenValue' %>
        <%= f.hidden_field :blue, :id => 'blueValue' %>
<% end %>

So I want this form to create a Color with the given parameters, and then create a SongColor connecting the newly created color, and the current song.