I want to show a page that lists people that belong to a particular company (each person has a company_id). My link_to looks like <%= link_to "people", :controller => "people", :action => "by_company", :company_id => @company.id %> which produces the link http://my-server-name/people/by_company?company_id=1 However, it errors with Couldn''t find Person with ID=by_company {"id"=>"by_company", "company_id"=>"1"} Why would the id be set to "by_company"? Shouldn''t that be the action? Thanks! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
How do you have this on your routes file? On Tue, Jun 22, 2010 at 7:34 PM, richardsugg <richardsugg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to show a page that lists people that belong to a particular > company (each person has a company_id). My link_to looks like > > <%= link_to "people", :controller => "people", :action => > "by_company", :company_id => @company.id %> > > which produces the link > > http://my-server-name/people/by_company?company_id=1 > > However, it errors with > > Couldn''t find Person with ID=by_company > {"id"=>"by_company", > "company_id"=>"1"} > > Why would the id be set to "by_company"? Shouldn''t that be the > action? > > Thanks! > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Routes file: ActionController::Routing::Routes.draw do |map| map.resources :people map.resources :users map.root :controller => "homepage" map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end'' On Jun 22, 2:51 pm, Rui Carvalho <rui.hmcarva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How do you have this on your routes file? > > > > On Tue, Jun 22, 2010 at 7:34 PM, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I want to show a page that lists people that belong to a particular > > company (each person has a company_id). My link_to looks like > > > <%= link_to "people", :controller => "people", :action => > > "by_company", :company_id => @company.id %> > > > which produces the link > > >http://my-server-name/people/by_company?company_id=1 > > > However, it errors with > > > Couldn''t find Person with ID=by_company > > {"id"=>"by_company", > > "company_id"=>"1"} > > > Why would the id be set to "by_company"? Shouldn''t that be the > > action? > > > Thanks! > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Well, I got around it, but I''d like to know why the original way didn''t work because I''m certain this will come up again. Here''s what I did: I changed the link_to to be <%= link_to "people", :controller => "people", :action => "by_company", :id => @company.id %> which created the link http://my-server-name/people/by_company/1 Thanks for looking at this. I''m sure this is a very easy question for someone who has done this a while, but that would not (yet) be me :) On Jun 22, 2:55 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Routes file: > > ActionController::Routing::Routes.draw do |map| > map.resources :people > map.resources :users > map.root :controller => "homepage" > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > end'' > > On Jun 22, 2:51 pm, Rui Carvalho <rui.hmcarva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > How do you have this on your routes file? > > > On Tue, Jun 22, 2010 at 7:34 PM, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I want to show a page that lists people that belong to a particular > > > company (each person has a company_id). My link_to looks like > > > > <%= link_to "people", :controller => "people", :action => > > > "by_company", :company_id => @company.id %> > > > > which produces the link > > > >http://my-server-name/people/by_company?company_id=1 > > > > However, it errors with > > > > Couldn''t find Person with ID=by_company > > > {"id"=>"by_company", > > > "company_id"=>"1"} > > > > Why would the id be set to "by_company"? Shouldn''t that be the > > > action? > > > > Thanks! > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
What do you have in your by_company method? looks like you had in your find statement - params[:id] and it should have been params[:company_id] You might take a look at generating a class method in your model file: def self.by_company( anId ) find(:all, :conditions => ["company_id = ?", anId] ) end The you can refer to this by Model_name.by_company( x ) Or a named scope - some things to look at. Hope this helps On Jun 22, 3:01 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, I got around it, but I''d like to know why the original way > didn''t work because I''m certain this will come up again. Here''s what > I did: > > I changed the link_to to be > > <%= link_to "people", :controller => "people", :action => > "by_company", :id => @company.id %> > > which created the link > > http://my-server-name/people/by_company/1 > > Thanks for looking at this. I''m sure this is a very easy question for > someone who has done this a while, but that would not (yet) be me :) > > On Jun 22, 2:55 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Routes file: > > > ActionController::Routing::Routes.draw do |map| > > map.resources :people > > map.resources :users > > map.root :controller => "homepage" > > map.connect '':controller/:action/:id'' > > map.connect '':controller/:action/:id.:format'' > > end'' > > > On Jun 22, 2:51 pm, Rui Carvalho <rui.hmcarva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > How do you have this on your routes file? > > > > On Tue, Jun 22, 2010 at 7:34 PM, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I want to show a page that lists people that belong to a particular > > > > company (each person has a company_id). My link_to looks like > > > > > <%= link_to "people", :controller => "people", :action => > > > > "by_company", :company_id => @company.id %> > > > > > which produces the link > > > > >http://my-server-name/people/by_company?company_id=1 > > > > > However, it errors with > > > > > Couldn''t find Person with ID=by_company > > > > {"id"=>"by_company", > > > > "company_id"=>"1"} > > > > > Why would the id be set to "by_company"? Shouldn''t that be the > > > > action? > > > > > Thanks! > > > > > -- > > > > 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@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
sure, if you wanted to name it ":company_id=>@company.id" then in the routes file you would have to do map.connect '':controller/:action/:company_id'' or else it will interpet as one cgi query parameter regards On Tue, Jun 22, 2010 at 8:01 PM, richardsugg <richardsugg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, I got around it, but I''d like to know why the original way > didn''t work because I''m certain this will come up again. Here''s what > I did: > > I changed the link_to to be > > <%= link_to "people", :controller => "people", :action => > "by_company", :id => @company.id %> > > which created the link > > http://my-server-name/people/by_company/1 > > Thanks for looking at this. I''m sure this is a very easy question for > someone who has done this a while, but that would not (yet) be me :) > > > On Jun 22, 2:55 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Routes file: > > > > ActionController::Routing::Routes.draw do |map| > > map.resources :people > > map.resources :users > > map.root :controller => "homepage" > > map.connect '':controller/:action/:id'' > > map.connect '':controller/:action/:id.:format'' > > end'' > > > > On Jun 22, 2:51 pm, Rui Carvalho <rui.hmcarva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > How do you have this on your routes file? > > > > > On Tue, Jun 22, 2010 at 7:34 PM, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > I want to show a page that lists people that belong to a particular > > > > company (each person has a company_id). My link_to looks like > > > > > > <%= link_to "people", :controller => "people", :action => > > > > "by_company", :company_id => @company.id %> > > > > > > which produces the link > > > > > >http://my-server-name/people/by_company?company_id=1 > > > > > > However, it errors with > > > > > > Couldn''t find Person with ID=by_company > > > > {"id"=>"by_company", > > > > "company_id"=>"1"} > > > > > > Why would the id be set to "by_company"? Shouldn''t that be the > > > > action? > > > > > > Thanks! > > > > > > -- > > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Gotcha! Thanks for your assistance! On Jun 23, 4:43 am, Rui Carvalho <rui.hmcarva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sure, > > if you wanted to name it ":company_id=>@company.id" > then in the routes file you would have to do > > map.connect '':controller/:action/:company_id'' > > or else it will interpet as one cgi query parameter > > regards > > > > On Tue, Jun 22, 2010 at 8:01 PM, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Well, I got around it, but I''d like to know why the original way > > didn''t work because I''m certain this will come up again. Here''s what > > I did: > > > I changed the link_to to be > > > <%= link_to "people", :controller => "people", :action => > > "by_company", :id => @company.id %> > > > which created the link > > >http://my-server-name/people/by_company/1 > > > Thanks for looking at this. I''m sure this is a very easy question for > > someone who has done this a while, but that would not (yet) be me :) > > > On Jun 22, 2:55 pm, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Routes file: > > > > ActionController::Routing::Routes.draw do |map| > > > map.resources :people > > > map.resources :users > > > map.root :controller => "homepage" > > > map.connect '':controller/:action/:id'' > > > map.connect '':controller/:action/:id.:format'' > > > end'' > > > > On Jun 22, 2:51 pm, Rui Carvalho <rui.hmcarva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > How do you have this on your routes file? > > > > > On Tue, Jun 22, 2010 at 7:34 PM, richardsugg <richards...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > > I want to show a page that lists people that belong to a particular > > > > > company (each person has a company_id). My link_to looks like > > > > > > <%= link_to "people", :controller => "people", :action => > > > > > "by_company", :company_id => @company.id %> > > > > > > which produces the link > > > > > >http://my-server-name/people/by_company?company_id=1 > > > > > > However, it errors with > > > > > > Couldn''t find Person with ID=by_company > > > > > {"id"=>"by_company", > > > > > "company_id"=>"1"} > > > > > > Why would the id be set to "by_company"? Shouldn''t that be the > > > > > action? > > > > > > Thanks! > > > > > > -- > > > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.