I''m using the restful2 application from the Agile Web Development with Rails and have added a search to the articles_controller.rb and added the route to the routes.rb as: map.resources :articles, :collection => {:search => :get } I need some help on how to call the function. I get the error: "no route found to match "/search" with {:method=>:get}" when using this code on the index.rhtml form: <form action="/search" > <input name ="Ndc" type="text" /> <input type=''Submit'' value=''search'' > </form> But this works in the address bar: http://localhost:3000/articles;search?Ndc=First How can I get the code in the index.rhtml to call correctly or what is the correct syntax for the form action? -- 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:> I''m using the restful2 application from the Agile Web Development with > Rails > and have added a search to the articles_controller.rb and added the > route to the routes.rb as: map.resources :articles, :collection => > {:search => :get } > > I need some help on how to call the function. I get the error: > "no route found to match "/search" with {:method=>:get}" > when using this code on the index.rhtml form: > <form action="/search" > > <input name ="Ndc" type="text" /> > <input type=''Submit'' value=''search'' > > </form> > > But this works in the address bar: > http://localhost:3000/articles;search?Ndc=First > > How can I get the code in the index.rhtml to call correctly or what is > the correct syntax for the form action?Hey, this works: <form action="articles;search" > <input name ="Ndc" type="text" /> <input type=''Submit'' value=''search'' > </form> Does anyone know a better way? -- 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 -~----------~----~----~----~------~----~------~--~---
On Aug 21, 2007, at 10:10 AM, David Allen wrote:> Hey, this works: > <form action="articles;search" > > <input name ="Ndc" type="text" /> > <input type=''Submit'' value=''search'' > > </form>Use the helpers? <% form_tag(search_articles_path) do %> <%= text_field_tag "Ndc" %> <%= submit_tag "Search" %> <% end %> (It may be articles_search_path instead of search_articles_path, I never can remember.) --~--~---------~--~----~------------~-------~--~----~ 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:>> <form action="/search" > >> <input name ="Ndc" type="text" /> >> <input type=''Submit'' value=''search'' > >> </form><form action="/search"> wont work because you dont have a route defined for it. In your routes.rb file you''ve told rails that the search action is a collection related to articles, so your URL would be: /articles;search If you want it to be /search then you''d need to add: map.search ''/search'', :controller => ''articles'', :action => ''search'' but then you''ll probably need to change your controller around. Might not work right off the bat. Read the peepcode rest cheat sheet. -- 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 -~----------~----~----~----~------~----~------~--~---