How can you implement a search function using the REST approach? Is there an example of this somewhere on the web? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nathan Esquenazi
2008-Mar-13 00:13 UTC
Re: User search thru a database using the REST approach
It would seem rather easy as far as you have two main options: 1) Think of the "search" itself as a resource 2) Think of the "search" as a condition of "index" action For one, create the SearchController which will manage "search" resources if you will. New will be the form to enter the search query, and "create" will perform the search and return the results, etc. For two, simply have the "index" action accept optional query conditions. So, by default, index would display all the items and then by specifying constraints, this could also act as a search of sorts. Hope that helps. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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, Nathan! I think I''m finally getting the hang of this REST approach and am starting to like it. Urls are so much cleaner and it''s starting to make sense! Cheri -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Good suggestion, Nathan. I think the main question (for Cheri) to answer is whether Search is something that is going to be needed for many different models or simply this one. If it''s something that will be done for many things and you need to render a consistent list then go with 1; if it''s primarily one (or two) models then go with 2. On Mar 12, 8:13 pm, Nathan Esquenazi <rails-mailing-l...@andreas- s.net> wrote:> It would seem rather easy as far as you have two main options: > > 1) Think of the "search" itself as a resource > 2) Think of the "search" as a condition of "index" action > > For one, create the SearchController which will manage "search" > resources if you will. New will be the form to enter the search query, > and "create" will perform the search and return the results, etc. > > For two, simply have the "index" action accept optional query > conditions. So, by default, index would display all the items and then > by specifying constraints, this could also act as a search of sorts. > > Hope that helps. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The search will be needed for just one model, so I will go with option 2. I also plan to include the search terms in the url for the search results view- which I assume under the REST model would be the search "show" view - so that the user can use the Back button to get back to the search results page. - Cheri AndyV wrote:> Good suggestion, Nathan. I think the main question (for Cheri) to > answer is whether Search is something that is going to be needed for > many different models or simply this one. If it''s something that will > be done for many things and you need to render a consistent list then > go with 1; if it''s primarily one (or two) models then go with 2. > > On Mar 12, 8:13 pm, Nathan Esquenazi <rails-mailing-l...@andreas--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---