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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Feb-27 06:36 UTC
Re: noob: how to pass parameters between pages in v2.0.2?
On 27 Feb 2008, at 02:10, Roy Pardee wrote:> > 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> 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roy Pardee
2008-Feb-27 17:11 UTC
Re: noob: how to pass parameters between pages in v2.0.2?
Sure enough--that fixes it. Thanks! On Feb 26, 10:36 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 27 Feb 2008, at 02:10, Roy Pardee wrote: > > > > > > > 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 > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---