views:

26

answers:

1

I want a search field to start outputting results once a user statrs typing

Here is what I got so far

 <%= observe_field 'keyword', :frequency => 0.5,
 :update => 'results',
 :loading => "Element.show('spinner')",
 :complete => "Element.hide('spinner')",
 :url => { :action=> 'search_results' } %>

then in my controller this is what i got. The text field is within a form i dont know if that makes a difference.

 def search_results
       keyword = params[:keyword]
       @tutors = Tutors.find(:all,:conditions => ["category LIKE ?", '%' + keyword + '%'])    
  end
A: 

If I understand your question correctly your action is not receiving the keyword as expected. Is this right? If so then it's because you need to add a :with argument to your observe_field call. Like this:

<%= observe_field 'keyword', 
    :frequency => 0.5,
    :update => 'results',
    :loading => "Element.show('spinner')",
    :complete => "Element.hide('spinner')",
    :url => { :action=> 'search_results' },
    :with => 'keyword' %>
bjg
Ok, I just did that and it doesnt do anything. Could it be because I am using jrails?
Alex
@Alex I believe jrails should mimic the same interface so I don't think that's it. What does your incoming `params` hash look like? Do you see any mention of `keyword`?
bjg
@bjg How would I check that?
Alex
@bjg http://avandata.net/tutor/tutors/search that is what I have if you type math and then click search you will see the results load. I basically want the same thing to happen except while the user is typing math, for the results to appear.
Alex
@Alex the javascript on that page looks like it should work so I don't know what's going on. You can check your incoming `params` value in your `log/development.log` file. You should see `keyword` posts coming in as you type in the form. One question. It's currently set up as a POST action. Is your `search_results` accepting POST or GET?
bjg
@bjg I believe it is coming in as GET and when you click the search button it as POST. When I click the search button it works. But the typing does not. I think my search_results is probably only accepting POST then. Here is my log/developmentProcessing TutorsController#search (for 98.254.132.228 at 2010-07-30 09:29:52) [GET]Rendering tutors/searchCompleted in 5ms (View: 3, DB: 0) | 200 OK [http://avandata.net/tutor/tutors/search]
Alex
@Alex. I see you reposted this with more information. I've commented some more under the new question
bjg