Ho problemi a generare un modulo di modello annidato.Ottenere campi_per lavorare con has_many relationship
Qui sono i miei modelli:
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
Nel controllore di allenamento, ecco quello che ho per la nuova azione:
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
Tuttavia, in forma, quando provo fields_for, I don niente:
<% f.fields_for :scores do |builder| %>
<p>
<%= builder.label :score %><br />
<%= builder.text_field :score %>
</p>
<% end %>
Cosa sto facendo male?
Cos'è 'Wod' e perché lo stai creando nel tuo controller di Workouts? –
Quello era un errore di battitura. Fisso! – Huey