Accessing directly to show action with a submit button

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs