noob: how to pass parameters between pages in v2.0.2?

Hey All,

I'm just starting out w/rails & have a toy app w/just 2 types of
things right now: People and Organizations. Person :belongs_to
organization and Organization :has_many people.

I've got scaffold-generated index views for both, which work well
(thanks in part to the kind help I've already gotten here). The index
page for organization shows the # of people that currently belong to
each one, and I even got fancy and made that number a hyperlink to the
people/index, w/view code like so:

  <td><%= link_to organization.people.count, "People", :action
=> :index %></td>

Now I want to get even fancier, and have people/index show me *just*
people belonging to the organization whose link was clicked. So I
figured I'd need to pass the people controller the proper organization
id, and have it do a proper Person.find() call.

I got the impression from the AWDWR book that I could just tack on an
extra hash value on my link_to call to pass the parameter, so I edited
the above to say:

  <td><%= link_to organization.people.count, "People", :action
=> :index, :org_id => organization.id %></td>

And then put this in PeopleController.index:

    if params[:org_id] then
      # raise("params[:org_id] IS defined!")
      @people = Person.find_by_organization(params[:org_id])
    else
      @people = Person.find(:all)
    end

But it seems that my parameter is *not* getting passed. If I dump a
params.inspect to the index page I see:

  {"action"=>"index", "controller"=>"people"}

Soooo... can anybody tell me the right way to move a parameter from
one page to another?

Thanks!

-Roy

Hey All,

I'm just starting out w/rails & have a toy app w/just 2 types of
things right now: People and Organizations. Person :belongs_to
organization and Organization :has_many people.

I've got scaffold-generated index views for both, which work well
(thanks in part to the kind help I've already gotten here). The index
page for organization shows the # of people that currently belong to
each one, and I even got fancy and made that number a hyperlink to the
people/index, w/view code like so:

<td><%= link_to organization.people.count, "People", :action
=> :index %></td>

Now I want to get even fancier, and have people/index show me *just*
people belonging to the organization whose link was clicked. So I
figured I'd need to pass the people controller the proper organization
id, and have it do a proper Person.find() call.

I got the impression from the AWDWR book that I could just tack on an
extra hash value on my link_to call to pass the parameter, so I edited
the above to say:

<td><%= link_to organization.people.count, "People", :action
=> :index, :org_id => organization.id %></td>

Your problem here is that if you pass 2 parameters to link_to like
that, it's going to assume that the first is some text and that the
second is the url (or part of it)

<%= link_to organization.people.count, :controller =>
'people", :action=> :index, :org_id => organization.id %>

should do the trick.

Fred

Sure enough--that fixes it. Thanks!