# Search form in custom method in RESTful

**URL:** <https://www.ruby-forum.com/t/search-form-in-custom-method-in-restful/179499>\
**Category:** Rails\
**Created:** [November 26, 2009, 11:05am UTC](https://www.ruby-forum.com/t/search-form-in-custom-method-in-restful/179499 "2009-11-26T11:05:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [November 26, 2009, 11:05am UTC](https://www.ruby-forum.com/t/search-form-in-custom-method-in-restful/179499/1 "2009-11-26T11:05:05Z")

</div>

I have a custom method in my controller for doing a search. How do I  
access that with a form\_for using restful?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [November 30, 2009, 9:45am UTC](https://www.ruby-forum.com/t/search-form-in-custom-method-in-restful/179499/2 "2009-11-30T09:45:28Z")

</div>

Hi PÃ¥l BergstrÃ¶m

```
Suppose your resource is Project and in routes.rb you have

```

map.resources :projects,:collection =\> {:search =\> :get}  
Now as you said you have the search action in projects controller  
Then the form\_for may be like this

\<% form\_for :project,:url =\> search\_projects\_path,:html =\> { :method =\>  
:get} do |f| %\>

\<% end %

But I think you can have form\_tag like  
\<% form\_tag projects\_path,:method =\> :get do %\>  
\<%= text\_field\_tag :search,params[:search] %\>  
\<%= submit\_tag “Search”,:name =\> nil%\>  
\<% end %\>

```
   This will point to index and the same index action you can use 

```

for search also

Sijo

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [November 30, 2009, 9:51am UTC](https://www.ruby-forum.com/t/search-form-in-custom-method-in-restful/179499/3 "2009-11-30T09:51:58Z")

</div>

Sijo k g wrote:

> Hi PÃ¥l BergstrÃ¶m

> ```
> This will point to index and the same index action you can use 
> 
> ```
> 
> for search also
> 
> Sijo

Thanks 🙂
