2010-05-26 75 views
1

以下內容位於text_field中。page.insert_html不能正確呈現部分

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

以下內容位於display_questions_search_results.rjs中。

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

無論何時用戶鍵入,我想在數據庫中搜索與文本字段中的關鍵字匹配的任何元組。然後,顯示這些結果。但是,目前,_suggestions.haml只包含單詞「suggestions !!」。

但是,並沒有看到「建議!!」在suggestions div標籤,我得到:

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

我一直在試圖找出爲什麼這個正在做,但以前提出的問題,我發現似乎比我在做什麼更復雜......

回答

2

如果指定要更新的元素,則假定您的操作將返回html(而不是rjs/javascript),它將替換指定元素的內容。

所以,如果你需要更換的:suggestions內容,只呈現在你的控制器部分:

render :partial => 'suggestions' 

但是,如果你需要的內容添加到這個元素,而不是取代,從您的視圖代碼中刪除:update => :suggestions

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

並留下控制器代碼是:

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