In using the restful2 example in Agile Development with Rails I thought it would be good to have a search function on title. So I added the search function to the controller with the other CRUD funtions. Added an input field to the index.rhtml page. I get the error "no route found ''/search''". And have not be able to come up with the syntax to add the route. Did I add the function to wrong place or how do you create the route? -- 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 -~----------~----~----~----~------~----~------~--~---
David Allen wrote:> In using the restful2 example in Agile Development with Rails I thought > it would be good to have a search function on title. So I added the > search function to the controller with the other CRUD funtions. Added > an input field to the index.rhtml page. I get the error "no route found > ''/search''". And have not be able to come up with the syntax to add the > route. Did I add the function to wrong place or how do you create the > route?Might help if you posted your routes so we can see what chew talking about... -- 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 -~----------~----~----~----~------~----~------~--~---
Dave Coleman wrote:> David Allen wrote: >> In using the restful2 example in Agile Development with Rails I thought >> it would be good to have a search function on title. So I added the >> search function to the controller with the other CRUD funtions. Added >> an input field to the index.rhtml page. I get the error "no route found >> ''/search''". And have not be able to come up with the syntax to add the >> route. Did I add the function to wrong place or how do you create the >> route? > > Might help if you posted your routes so we can see what chew talking > about...routes.rb: #--- # Excerpted from "Agile Web Development with Rails, 2nd Ed." # We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information. #--- ActionController::Routing::Routes.draw do |map| map.resources :articles do |article| article.resources :comments end And the serarch function in articles_controller.rb: # GET /articles/l # GET /articles/l.xml def search if params[:Ndc] @article = Article.find(:all, conditions => ["title like ?", "%#{params[:Ndc]}%"]).each else @artivle = [] end respond_to do |format| format.html # show.rhtml format.xml { render :xml => @article.to_xml } end end end -- 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 -~----------~----~----~----~------~----~------~--~---
> ActionController::Routing::Routes.draw do |map| > map.resources :articles do |article| > article.resources :comments > end >see what happens when u change the above to: map.resources :articles do |article| article.resources :comments article.resources :search end -- 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 -~----------~----~----~----~------~----~------~--~---
> see what happens when u change the above to: > > map.resources :articles do |article| > article.resources :comments > article.resources :search > endok. if was actually thinking I wouldn''t have typed that :-) sorry, ignore the previous post. try: map.resources :articles, :collection => { :search => :get } do |article| article.resources :comments end Hopefully im right this time... -- 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 -~----------~----~----~----~------~----~------~--~---
Dave Coleman wrote:>> see what happens when u change the above to: >> >> map.resources :articles do |article| >> article.resources :comments >> article.resources :search >> end > > ok. if was actually thinking I wouldn''t have typed that :-) > > sorry, ignore the previous post. > > try: > > map.resources :articles, :collection => { :search => :get } do > |article| > article.resources :comments > end > > Hopefully im right this time...Yes, I did try that and dropped off the comments. Got an error that collection was not defined. This is where I cannot find any good docs on how the routes work. -- 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 -~----------~----~----~----~------~----~------~--~---
> Yes, I did try that and dropped off the comments. Got an error that > collection was not defined. This is where I cannot find any good docs > on how the routes work.http://peepcode.com/products/restful-rails and http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf might help. -- 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 -~----------~----~----~----~------~----~------~--~---
> Yes, I did try that and dropped off the comments. Got an error that > collection was not defined. This is where I cannot find any good docs > on how the routes work.and ... http://railscasts.com/episodes/35 -- 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 -~----------~----~----~----~------~----~------~--~---