Q:

Rails nested model with formtastic is skipping one field?

I have this structure models 
class Tournament < ActiveRecord::Base
  AGES = ["5u", "6u", "7u", "8u"]
  has_many  :courts, :dependent => :destroy
  accepts_nested_attributes_for :courts, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true

class Court < ActiveRecord::Base
  belongs_to :tournament, :autosave => true
  has_many  :ages, :dependent => :destroy
  accepts_nested_attributes_for :ages, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true

class Age < ActiveRecord::Base
  belongs_to :court

Now my forms look like this 
_form.html.erb
<%= semantic_form_for @tournament do |f| %>
<%= f.inputs do %>
  <%= f.input :name, :hint => "What is the name of the Tournament?" %>
<%= f.semantic_fields_for :courts do |builder| %>
       <%= render :partial => "court_fields", :locals => { :f => builder } %>
   <% end %>

_court_fields.html.erb
<div class="nested_fields">
<%= f.input :name, :input_html => {:class => "name"} %>
<%= f.semantic_fields_for :ages do |builder| %>
  <%= render :partial => "age_fields", :locals => { :f => builder } %>
<% end %>

_age_fields.html.erb
 Testing ...am I getting in here
<%= f.input :name, :as => :check_boxes, :collection => Tournament::AGES, :input_html => {:class => "age_limits"} %>

everything seems to work well except nothing shows up in the ages_fields partial...not the checkboxes and not even the dummy text Testing ...am I getting in here is not displaying....any ideas what could be causing the issue 

A:

The obvious reason I can think of: are you sure your Court has ages ?
[EDIT] That the Court has the relation was indeed clear to me. 
But your code will only show an age for a court if it already exists.
From your output in the comments: the court has no actual ages so no ages are shown.
If you do this in your controller:
def new
  @tournament = Tournament.new
  @tournament.courts.build
  @tournament.courts[0].ages.build  
end

This will make sure that you have at least one (empty) court and one (empty) age. 
Otherwise you could also consider using a gem like cocoon to dynamically add new elements if needed.
Hope this helps.

