Observe_field and disptcher problem


#1

Hello everyone,

I am trying to make live-search list with observe_field and I still have
the problem with invoking the proper action.

Take a look at the following code:

index.html.erb:

<%= text_field_tag “search” %>
<%= observe_field ‘search’, :url => {:action => “search_list”},
:frequency => 0.5,
:update => ‘transactions_list’,
:with => “‘text=’ + escape(value)”
%>

transactions_controller.rb:

def search_list
if params[:text]
@transactions = Transaction.find(:all, :order => “created_at
DESC”, :conditions => [ ‘LOWER(name) LIKE ?’, ‘%’ +
params[:text].downcase + ‘%’ ]).reverse
render :partial => ‘transactions_list’
else
@transactions = Transaction.find(:all, :order => “created_at
DESC”).reverse
render :partial => ‘transactions_list’
end
end

When I am trying to type something into the text_field, the framework
invokes “show” action instead of “search_list”.

Take a look at the following logs - it doesn’t make sense to me.


Processing TransactionsController#show (for 127.0.0.1 at 2008-12-10
14:58:42) [GET]
Parameters: {“text”=>“greg”,
“authenticity_token”=>“484c0acdba12c67bfd3e842206db6fa122163fca”,
“id”=>“search_list”}
Rendering transactions/show
Completed in 9ms (View: 4, DB: 0) | 200 OK
[http://localhost/transactions/search_list?text=gregauthenticity_token=484c0acdba12c67bfd3e842206db6fa122163fca]

Any suggestions?

Thanks in advance


#2

hi,

i am very new to rails but i have implemented live search using ajax
the same way you tried .

try this out:but i am not sure

def search_list
if params[:text]
@transactions = Transaction.find(:all, :order => “created_at
DESC”, :conditions => [ ‘LOWER(name) LIKE ?’, ‘%’ +
params[:text].downcase + ‘%’ ]).reverse
else
flash[:notice] = ‘not found.’

 render :partial => 'transactions_list'

else
render :partial => ‘index’
end
end

thnaks
srikanth

On Wed, Dec 10, 2008 at 8:07 PM, Gregory P.