# School Years/Teams listing problem

**URL:** <https://www.ruby-forum.com/t/school-years-teams-listing-problem/58715>\
**Category:** Rails\
**Created:** [April 25, 2006, 7:36am UTC](https://www.ruby-forum.com/t/school-years-teams-listing-problem/58715 "2006-04-25T07:36:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [April 25, 2006, 7:36am UTC](https://www.ruby-forum.com/t/school-years-teams-listing-problem/58715/1 "2006-04-25T07:36:31Z")

</div>

People,

I have tables years and teams and I have the years listing like:

1965  
1966  
1967  
.  
.

I want to be able to click on the year and ONLY list teams for that  
year. At first I thought the following was working until I started  
populating the table with teams for more than one year.

For views/years/list.rhtml:

\<% for year in @years %\>

 \<%= link\_to year.name, :controller=\>"teams", :action =\> "list", :year\_id =\> "#{year.id}" %\>

but it doesn’t matter what year I click on, I get all possible teams . .  
I have tried various permutations but can’t see how to do it. My tables  
look like (in table years, I have set the id to be the same as the name  
eg 1965):

Table “public.years”  
id | integer  
name | integer

Table “public.teams”  
id | integer  
name | character varying  
year\_id | integer

Any help appreciated!

Regards,

## Phil.

Philip R.

Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)  
GPO Box 3411  
Sydney NSW 2001  
Australia  
Mobile: +61:(0)411-185-652  
Fax: +61:(0)2-8221-9599  
E-mail: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [May 3, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/school-years-teams-listing-problem/58715/2 "2006-05-03T18:57:43Z")

</div>

On 4/25/06, Philip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to be able to click on the year and ONLY list teams for that  
> year. At first I thought the following was working until I started  
> populating the table with teams for more than one year.

> but it doesn’t matter what year I click on, I get all possible teams . .

What does the code in your controller for filling @years look like? It  
should have a condition to limit by the parameter that has the year  
ID.

> Regards,
> 
> Phil.

Sincerely,

Tom L.  
[http://AllTom.com/](http://AllTom.com/)  
[http://GadgetLife.org/](http://GadgetLife.org/)

---

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [May 3, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/school-years-teams-listing-problem/58715/3 "2006-05-03T18:57:45Z")

</div>

Tom,

On Mon, 2006-05-01 at 11:48 -0400, Tom L. wrote:

> > I want to be able to click on the year and ONLY list teams for that  
> > year. At first I thought the following was working until I started  
> > populating the table with teams for more than one year.
> 
> > but it doesn’t matter what year I click on, I get all possible teams . .
> 
> What does the code in your controller for filling @years look like? It  
> should have a condition to limit by the parameter that has the year  
> ID.

It is just:

def list  
@year\_pages, @years = paginate :years, :per\_page =\> 20  
@years = Year.find\_all  
@teams = Team.find\_all  
end

- but to begin with, all years _should_ display, it is only after  
clicking on a year that all teams for that year only should then  
display . .

Someone else suggested this is a HABTM situation so I was going to look  
at that next . .

Thanks for the response!

Regards,

## Phil.

Philip R.

Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)  
GPO Box 3411  
Sydney NSW 2001  
Australia  
Mobile: +61:(0)411-185-652  
Fax: +61:(0)2-8221-9599  
E-mail: removed\_email\_address@domain.invalid
