我通过选项使用 rails has_many 并且不确定我是否在这里做错了什么。我希望玩家创建一个赛季,当一个玩家即将创建一个赛季时,它将显示我在年/新创建的所有赛季的选择菜单。到目前为止,这部分工作得很好,但是当玩家试图拯救赛季轨道时并没有拯救它。我不确定我的关联是正确的还是我做错了什么?有什么理由不工作吗?
错误
No association found for name `season_year'. Has it been defined yet?
季节.rb
class season < ActiveRecord::Base
belongs_to :player
has_many :quarters
has_many :years , :through => :quarters
attr_accessible :season_year_attributes
accepts_nested_attributes_for :season_year
end
四分之一.rb
class Quarter < ActiveRecord::Base
belongs_to :player
belongs_to :year
belongs_to :season
end
年.rb
class Year < ActiveRecord::Base
attr_accessible :season_year, :season_name
has_many :quarters
has_many :seasons, :through => :quarters
end
播放器.rb
class player < ActiveRecord::Base
has_many :seasons, :through => :quarters
has_many :years, :through => :quarters
end
_season-form.html.erb
<%= form_for(@season) do |f| %>
<div class="field">
<%= f.label :season %>
<%= f.text_field :season_name %>
</div>
<%= f.fields_for :years do |year| %>
<%= select("season", "year_ids", Year.all.collect {|p| [ p.season_year, p.id ] }, { :include_blank => true }) %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>