Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:33:22+00:00 2026-06-02T22:33:22+00:00

I am using rails has_many through options and not sure if I am doing

  • 0

I am using rails has_many through options and not sure if I am doing something wrong here. I would like for a player to create a season and when a player is about to create a season it will show a select menu of all the seasons I have created in years/new. So far that part has worked great but when a player try’s to save the season rails does not save it. I am not sure if my association is correct or if I am doing something wrong? Is there any reason why this is not working?

error

No association found for name `season_year'. Has it been defined yet?

season.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

quarter.rb

class Quarter < ActiveRecord::Base
  belongs_to :player
  belongs_to :year
  belongs_to :season
end

year.rb

class Year < ActiveRecord::Base
  attr_accessible :season_year, :season_name

  has_many :quarters
  has_many :seasons, :through => :quarters 
end

player.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 %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:33:25+00:00Added an answer on June 2, 2026 at 10:33 pm

    Based on your models, I believe you need to change this:

    accepts_nested_attributes_for :season_year 
    

    to this:

    accepts_nested_attributes_for :years
    

    When you accept nested attributes it is for a Model and not a property of a model (season_year is an attribute of the year model versus accepting the nested attributes for the actual model, Year).

    EDIT:

    In the Season model, I added year_ids to the attr_accessible expression:

    attr_accessible :season_year_attributes, :year_ids
    

    I also altered the season form so that the output of the select list for years was only this:

    <%= select("season", "year_ids", Year.all.collect {|p| [ p.title, p.id ] }, { :include_blank => true }) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the Rails associations guide, they demonstrate a many-to-many relationship using has_many :through like
I'm learning Ruby on Rails. I'm using some associations (has_many :through, ...) But i'm
In Rails - what is the effect of using has_many :through with has_and_belongs_to_many? Consider
I was previously using has_and_belongs_to_many, and have converted to has_many :through. Here's how it
I am using Ruby on Rails 3.0.7 and I would like to use check
I am using Ruby on Rails 3.0.7 and I would like to keep the
I'm trying to recreate a has_many :through relationship (like in Rails) with Objective-C, if
I am using Ruby on Rails 3 and I would like to set a
I am using Ruby on Rails 3.0.10 and I would like to improve some
Is there anything explicitly wrong with using has_and_belongs_to_many associations in rails instead of has_many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.