# Singular\_path calling index instead of show using a GET

**URL:** <https://www.ruby-forum.com/t/singular-path-calling-index-instead-of-show-using-a-get/128669>\
**Category:** Rails\
**Created:** [February 10, 2008, 4:25am UTC](https://www.ruby-forum.com/t/singular-path-calling-index-instead-of-show-using-a-get/128669 "2008-02-10T04:25:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 10, 2008, 4:25am UTC](https://www.ruby-forum.com/t/singular-path-calling-index-instead-of-show-using-a-get/128669/1 "2008-02-10T04:25:33Z")

</div>

I have a general query page that contains the following:

\<% form\_tag(search\_url(@id), :method =\> :get) do %\>  
\<%= text\_field\_tag(:id, ‘’, :size =\> 25) %\>

\<%= submit\_tag "Search Database" %\>

\<% end %\>

I want the URL to be serial\_number/A1234 and it performs the search.  
That works in my controller. But the page wants to call index with a  
query string. I know and have as a hack redirect from index to show,  
but that just slows it down because of the redirect. I also can  
duplicate the code in both index and show, but that is not very DRY.

The controller is this:

# GET /search

# GET /search.xml

def index  
redirect\_to(:action =\> ‘show’, :id =\> params[:id]) unless  
params[:id].nil?  
end

# GET /search/:id :id is search serial number

# GET /search/:id.xml

def show  
unless params[:id].nil?  
@items = tem.by\_serial\_number(params[:id])  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @items }  
end  
end  
end

Also, is there a way to change the default parameter from id to  
something that is more intelligent like in this case “serial\_number”  
or sn?

Don F.

---

<div class="post-metadata">

**Author:** ![Don\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Don\_F](https://www.ruby-forum.com/u/Don_F)\
**Post date:** [February 10, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/singular-path-calling-index-instead-of-show-using-a-get/128669/2 "2008-02-10T20:38:14Z")

</div>

bump

Any Ideas?

Don F.
