# Accessing directly to show action with a submit button

**URL:** <https://www.ruby-forum.com/t/accessing-directly-to-show-action-with-a-submit-button/123009>\
**Category:** Rails\
**Created:** [December 13, 2007, 11:34am UTC](https://www.ruby-forum.com/t/accessing-directly-to-show-action-with-a-submit-button/123009 "2007-12-13T11:34:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 13, 2007, 11:34am UTC](https://www.ruby-forum.com/t/accessing-directly-to-show-action-with-a-submit-button/123009/1 "2007-12-13T11:34:53Z")

</div>

Hi everybody!

I’m working on a google-like search engine, using Ferret to index  
documents on a smb share.  
Everything works fine, but I still would like to get rid of the  
useless action ‘check\_query’, that doesn’t do anything else than  
redirecting to ‘show’ with an id parameter (queries don’t need to be  
checked/sanitized for Ferret AFAIK).

# documents\_controller.rb

…  
def check\_query  
redirect\_to :action=\>‘show’, :id=\>params[:query]  
end

def show  
@query=params[:id]  
…  
########################################################

# documents/index.haml

…  
-form\_tag(:action=\>:check\_query) do  
= text\_field\_tag :query, @query, :size=\>60, :class=\>‘text\_field’  
= submit\_tag “Search!”, :class =\> ‘btn’  
…  
########################################################

# routes.rb

ActionController::Routing::Routes.draw do |map|  
map.resources :documents, :collection=\>{:check\_query=\>:post},  
:member=\>{:download=\>:get}  
map.connect ‘documents/:id’, :controller=\>‘documents’,  
:action=\>‘show’, :id =\> /.\*/  
…  
#########################################################

I use this check\_query action only because I didn’t succeed in  
configuring form\_tag to send “get” method with id parameter = query.  
I tried

-form\_tag({:action=\>:show},{:method=\>:get}) do  
= text\_field\_tag :id, @query, :size=\>60, :class=\>‘text\_field’

without success… The submit button redirects to :index with those  
parameters:  
{“commit”=\>“Search!”, “action”=\>“index”, “id”=\>“some query”,  
“controller”=\>“documents”}

Do you know by any chance how I could do this?

Thanks,  
Eric
