views:

184

answers:

1

The following is in the text_field.

= f.text_field :title, :size => 50, :onchange => remote_function(:update => :suggestions, :url => {:action => :display_question_search_results})

The following is in display_questions_search_results.rjs.

page.insert_html :bottom, 'suggestions', :partial => 'suggestions'

Whenever the user types, I'd like to search the database for any tuples that match the keywords in the text field. Then, display those results. But, at the moment, _suggestions.haml only contains the word "suggestions!!".

But, instead of seeing "suggestions!!" in the suggestions div tag, I get:

try { Element.insert("suggestions", { bottom: "suggestions!!" }); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.insert(\"suggestions\", { bottom: \"suggestions!!\" });'); throw e }

I've been trying to find out why this is being done, but the previously asked questions I found seem more complicated than what I'm doing...

+1  A: 

If you specify element to update, it is assumed that your action will return html (not rjs/javascript), that will replace contents of specified element.

So, if you need to replace contents of :suggestions, just render partial in your controller:

render :partial => 'suggestions'

But if you need to add contents to this element, not to replace, remove :update => :suggestions from your view code:

= f.text_field :title, :size => 50, :onchange => remote_function(:url => {:action => :display_question_search_results})

And leave controller code as is:

page.insert_html :bottom, 'suggestions', :partial => 'suggestions'
Voyta