Forum: Ruby on Rails School Years/Teams listing problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
55f28e9c77b35b1539af6be60986b0e4?d=identicon&s=25 Philip Rhoades (Guest)
on 2006-04-25 07:36
(Received via mailing list)
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 %>
  <tr>
    <td>
        <%= 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 Rhoades

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:  phil@pricom.com.au
7a28bf7b0932a9486c21f1a33eb431ba?d=identicon&s=25 Tom Lieber (Guest)
on 2006-05-03 18:57
(Received via mailing list)
On 4/25/06, Philip Rhoades <phil@pricom.com.au> 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 Lieber
http://AllTom.com/
http://GadgetLife.org/
55f28e9c77b35b1539af6be60986b0e4?d=identicon&s=25 Philip Rhoades (Guest)
on 2006-05-03 18:57
(Received via mailing list)
Tom,


On Mon, 2006-05-01 at 11:48 -0400, Tom Lieber 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 Rhoades

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:  phil@pricom.com.au
This topic is locked and can not be replied to.