given the following code snippet: class PatientsController < ApplicationController ... def find @patients = Patient.find(:all, :conditions => { :location => [params:search_string] }) end I would like to add a few hard coded links (i.e. show me all the patients in a particular location) This makes sense to me: <% link_to "=Hospital 1 census", {:controller=>"/ patients", :action=>"find", :search_string=>"Hospital 1"} %> but gives me error "Couldn''t find Patient with ID=find" (The above link generates the URL example.com/patients/find? search_string=Hillcrest) I tried playing around with routes.rb, but got nowhere. What am I doing wrong? Thanks, --b
The way you are receiving parameter is wrong it should be like this @patients = Patient.find(:all, :conditions => { :location =>params [:search_string] }) GUL On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> given the following code snippet: > > class PatientsController < ApplicationController > ... > def find > @patients = Patient.find(:all, :conditions => { :location => > [params:search_string] }) > end > > I would like to add a few hard coded links (i.e. show me all the > patients in a particular location) > > This makes sense to me: > > <% link_to "=Hospital 1 census", {:controller=>"/ > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > but gives me error "Couldn''t find Patient with ID=find" (The above > link generates the URL example.com/patients/find? > search_string=Hillcrest) > > I tried playing around with routes.rb, but got nowhere. What am I > doing wrong? > > Thanks, > --b
On May 6, 8:40 am, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > <% link_to "=Hospital 1 census", {:controller=>"/ > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > but gives me error "Couldn''t find Patient with ID=find" (The above > link generates the URL example.com/patients/find? > search_string=Hillcrest) > > I tried playing around with routes.rb, but got nowhere. What am I > doing wrong?In addition to what Gul has said, assuming you have the default map.resources :patients then you need to tell rails about your find action ( take a look at the routing guide at guides.rubyonrails.org (hint: :collection )) Fred> > Thanks, > --b
sorry, that''s a typo. it appears the way you suggested in my code (it compiles). i''ll look into the routing some more, i was ready to bash my head in last night and couldn''t take it any more... --b On May 6, 12:59 am, Gul <jhangers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The way you are receiving parameter is wrong it should be like this > > @patients = Patient.find(:all, :conditions => { :location =>params > [:search_string] }) > > GUL > > On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > given the following code snippet: > > > class PatientsController < ApplicationController > > ... > > def find > > @patients = Patient.find(:all, :conditions => { :location => > > [params:search_string] }) > > end > > > I would like to add a few hard coded links (i.e. show me all the > > patients in a particular location) > > > This makes sense to me: > > > <% link_to "=Hospital 1 census", {:controller=>"/ > > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > > but gives me error "Couldn''t find Patient with ID=find" (The above > > link generates the URL example.com/patients/find? > > search_string=Hillcrest) > > > I tried playing around with routes.rb, but got nowhere. What am I > > doing wrong? > > > Thanks, > > --b
Since find is not one of the standard actions, have you included a specific route for patients/find? The default routes generated by map.resources :patients will assume that find is a patient id, expecting to see patients/2 for example. Colin 2009/5/6 big poppa <cbnewman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > sorry, that''s a typo. it appears the way you suggested in my code (it > compiles). > > i''ll look into the routing some more, i was ready to bash my head in > last night and couldn''t take it any more... > > --b > > On May 6, 12:59 am, Gul <jhangers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > The way you are receiving parameter is wrong it should be like this > > > > @patients = Patient.find(:all, :conditions => { :location =>params > > [:search_string] }) > > > > GUL > > > > On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > given the following code snippet: > > > > > class PatientsController < ApplicationController > > > ... > > > def find > > > @patients = Patient.find(:all, :conditions => { :location => > > > [params:search_string] }) > > > end > > > > > I would like to add a few hard coded links (i.e. show me all the > > > patients in a particular location) > > > > > This makes sense to me: > > > > > <% link_to "=Hospital 1 census", {:controller=>"/ > > > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > > > > but gives me error "Couldn''t find Patient with ID=find" (The above > > > link generates the URL example.com/patients/find? > > > search_string=Hillcrest) > > > > > I tried playing around with routes.rb, but got nowhere. What am I > > > doing wrong? > > > > > Thanks, > > > --b > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Having thought further about this I would suggest that you may going about it the wrong way anyway. I think what you are trying to do is select a set of patients for display. The default action for showing a set of patients is the index action, which by default would show all patients and is accessed by example.com/patients. You could use the URL example.com/patients?search_string=Hillcrest (or whatever) and test for the presence of params[:search_string] in the index method of the controller. Then no special routing is required. Colin 2009/5/7 Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> Since find is not one of the standard actions, have you included a specific > route for patients/find? The default routes generated by map.resources > :patients will assume that find is a patient id, expecting to see patients/2 > for example. > > Colin > > 2009/5/6 big poppa <cbnewman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> sorry, that''s a typo. it appears the way you suggested in my code (it >> compiles). >> >> i''ll look into the routing some more, i was ready to bash my head in >> last night and couldn''t take it any more... >> >> --b >> >> On May 6, 12:59 am, Gul <jhangers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > The way you are receiving parameter is wrong it should be like this >> > >> > @patients = Patient.find(:all, :conditions => { :location =>params >> > [:search_string] }) >> > >> > GUL >> > >> > On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > > given the following code snippet: >> > >> > > class PatientsController < ApplicationController >> > > ... >> > > def find >> > > @patients = Patient.find(:all, :conditions => { :location => >> > > [params:search_string] }) >> > > end >> > >> > > I would like to add a few hard coded links (i.e. show me all the >> > > patients in a particular location) >> > >> > > This makes sense to me: >> > >> > > <% link_to "=Hospital 1 census", {:controller=>"/ >> > > patients", :action=>"find", :search_string=>"Hospital 1"} %> >> > >> > > but gives me error "Couldn''t find Patient with ID=find" (The above >> > > link generates the URL example.com/patients/find? >> > > search_string=Hillcrest) >> > >> > > I tried playing around with routes.rb, but got nowhere. What am I >> > > doing wrong? >> > >> > > Thanks, >> > > --b >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thanks for your input and thoughtful reply. I like your proposal and I''ll give it a shot Thanks, --b On May 7, 6:39 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Having thought further about this I would suggest that you may going about > it the wrong way anyway. I think what you are trying to do is select a set > of patients for display. The default action for showing a set of patients > is the index action, which by default would show all patients and is > accessed by example.com/patients. You could use the URL > example.com/patients?search_string=Hillcrest (or whatever) and test for the > presence of params[:search_string] in the index method of the controller. > Then no special routing is required. > > Colin > > 2009/5/7 Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > > Since find is not one of the standard actions, have you included a specific > > route for patients/find? The default routes generated by map.resources > > :patients will assume that find is a patient id, expecting to see patients/2 > > for example. > > > Colin > > > 2009/5/6 big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> sorry, that''s a typo. it appears the way you suggested in my code (it > >> compiles). > > >> i''ll look into the routing some more, i was ready to bash my head in > >> last night and couldn''t take it any more... > > >> --b > > >> On May 6, 12:59 am, Gul <jhangers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > The way you are receiving parameter is wrong it should be like this > > >> > @patients = Patient.find(:all, :conditions => { :location =>params > >> > [:search_string] }) > > >> > GUL > > >> > On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > > given the following code snippet: > > >> > > class PatientsController < ApplicationController > >> > > ... > >> > > def find > >> > > @patients = Patient.find(:all, :conditions => { :location => > >> > > [params:search_string] }) > >> > > end > > >> > > I would like to add a few hard coded links (i.e. show me all the > >> > > patients in a particular location) > > >> > > This makes sense to me: > > >> > > <% link_to "=Hospital 1 census", {:controller=>"/ > >> > > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > >> > > but gives me error "Couldn''t find Patient with ID=find" (The above > >> > > link generates the URL example.com/patients/find? > >> > > search_string=Hillcrest) > > >> > > I tried playing around with routes.rb, but got nowhere. What am I > >> > > doing wrong? > > >> > > Thanks, > >> > > --b
Suppose I wanted to do this. Wouldn''t the syntax be (in config/ routes.rb) map.connect ''/patients/find'', :controller=>''patient'', :action=>''find'' prepended to the standard, scaffold generated map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' --b On May 7, 12:06 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Since find is not one of the standard actions, have you included a specific > route for patients/find? The default routes generated by map.resources > :patients will assume that find is a patient id, expecting to see patients/2 > for example. > > Colin > > 2009/5/6 big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > sorry, that''s a typo. it appears the way you suggested in my code (it > > compiles). > > > i''ll look into the routing some more, i was ready to bash my head in > > last night and couldn''t take it any more... > > > --b > > > On May 6, 12:59 am, Gul <jhangers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > The way you are receiving parameter is wrong it should be like this > > > > @patients = Patient.find(:all, :conditions => { :location =>params > > > [:search_string] }) > > > > GUL > > > > On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > given the following code snippet: > > > > > class PatientsController < ApplicationController > > > > ... > > > > def find > > > > @patients = Patient.find(:all, :conditions => { :location => > > > > [params:search_string] }) > > > > end > > > > > I would like to add a few hard coded links (i.e. show me all the > > > > patients in a particular location) > > > > > This makes sense to me: > > > > > <% link_to "=Hospital 1 census", {:controller=>"/ > > > > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > > > > but gives me error "Couldn''t find Patient with ID=find" (The above > > > > link generates the URL example.com/patients/find? > > > > search_string=Hillcrest) > > > > > I tried playing around with routes.rb, but got nowhere. What am I > > > > doing wrong? > > > > > Thanks, > > > > --b
2009/5/7 big poppa <cbnewman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > Suppose I wanted to do this. Wouldn''t the syntax be (in config/ > routes.rb) > > map.connect ''/patients/find'', :controller=>''patient'', :action=>''find''Make sure it is before map.resources :patient otherwise this will be seen first and you will get the problem you have described. Also I do not put a leading / when using map.connect but I do not know whether that is an issue or not. So I would put map.connect ''patients/find'' .... Use rake routes to show you the current mapping. Colin> > prepended to the standard, scaffold generated > > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > > --b > > On May 7, 12:06 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > Since find is not one of the standard actions, have you included a > specific > > route for patients/find? The default routes generated by map.resources > > :patients will assume that find is a patient id, expecting to see > patients/2 > > for example. > > > > Colin > > > > 2009/5/6 big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > > > > > sorry, that''s a typo. it appears the way you suggested in my code (it > > > compiles). > > > > > i''ll look into the routing some more, i was ready to bash my head in > > > last night and couldn''t take it any more... > > > > > --b > > > > > On May 6, 12:59 am, Gul <jhangers...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > The way you are receiving parameter is wrong it should be like this > > > > > > @patients = Patient.find(:all, :conditions => { :location =>params > > > > [:search_string] }) > > > > > > GUL > > > > > > On May 6, 12:40 pm, big poppa <cbnew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > given the following code snippet: > > > > > > > class PatientsController < ApplicationController > > > > > ... > > > > > def find > > > > > @patients = Patient.find(:all, :conditions => { :location => > > > > > [params:search_string] }) > > > > > end > > > > > > > I would like to add a few hard coded links (i.e. show me all the > > > > > patients in a particular location) > > > > > > > This makes sense to me: > > > > > > > <% link_to "=Hospital 1 census", {:controller=>"/ > > > > > patients", :action=>"find", :search_string=>"Hospital 1"} %> > > > > > > > but gives me error "Couldn''t find Patient with ID=find" (The above > > > > > link generates the URL example.com/patients/find? > > > > > search_string=Hillcrest) > > > > > > > I tried playing around with routes.rb, but got nowhere. What am I > > > > > doing wrong? > > > > > > > Thanks, > > > > > --b > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---