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.