Forum: Ruby on Rails observe_field and disptcher problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
374ff27591e5f55ebf0d6f55190a610c?d=identicon&s=25 Gregory Peck (gringo8)
on 2008-12-10 15:37
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=gre...]
------------------------------------------------------------------------

Any suggestions?

Thanks in advance
E38118c6d20b4544e424fd700571e090?d=identicon&s=25 sreekanth.G (Guest)
on 2008-12-11 06:01
(Received via mailing list)
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 Peck
This topic is locked and can not be replied to.