I'm having trouble generating a nested model form.
Here are my models:
class Workout < ActiveRecord::Base
has_many :scores
has_many :users, :through => :scores
accepts_nested_attributes_for :scores
end
class Score < ActiveRecord::Base
belongs_to :user
belongs_to :workout
end
class User < ActiveRecord::Base
has_many :scores
has_many :workout, :through => :scores
end
In the Workout controller, here's what I have for the new action:
def new
@workout = Workout.new
3.times { @workout.scores.build }
respond_to do |format|
format.html # new.html.erb
format.json { render json: @wod }
end
end
However, in the form, when I try fields_for, I don't get anything:
<% f.fields_for :scores do |builder| %>
<p>
<%= builder.label :score %><br />
<%= builder.text_field :score %>
</p>
<% end %>
What am I doing wrong?