# I'm almost there, just need a small push

**URL:** <https://www.ruby-forum.com/t/im-almost-there-just-need-a-small-push/112632>\
**Category:** Rails\
**Created:** [August 21, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/im-almost-there-just-need-a-small-push/112632 "2007-08-21T16:59:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [August 21, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/im-almost-there-just-need-a-small-push/112632/1 "2007-08-21T16:59:18Z")

</div>

I’m using the restful2 application from the Agile Web D. 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:

But this works in the address bar:  
[http://localhost:3000/articles;search?Ndc=First](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?

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [August 21, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/im-almost-there-just-need-a-small-push/112632/2 "2007-08-21T17:10:31Z")

</div>

David Allen wrote:

> I’m using the restful2 application from the Agile Web D. 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:
> 
> But this works in the address bar:  
> [http://localhost:3000/articles;search?Ndc=First](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:

Does anyone know a better way?

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [August 21, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/im-almost-there-just-need-a-small-push/112632/3 "2007-08-21T18:31:14Z")

</div>

On Aug 21, 2007, at 10:10 AM, David Allen wrote:

> Hey, this works:

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.)

---

<div class="post-metadata">

**Author:** ![mickey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@mickey](https://www.ruby-forum.com/u/mickey)\
**Post date:** [August 21, 2007, 6:59pm UTC](https://www.ruby-forum.com/t/im-almost-there-just-need-a-small-push/112632/4 "2007-08-21T18:59:59Z")

</div>

David Allen wrote:

> >

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.
