2009-12-01 56 views
0
<p>Song Name:<%= text_field :songlists, :song_name, :id => "songlists_" + section.id.to_s + "_song_name" %></p> 

<%= auto_complete_field "songlists_" + section.id.to_s + "_song_name", :method => :get, 
     :with => "'search=' + element.value", :url => formatted_songlists_path(:js) %> 

<p>Artist:<%= text_field :songlists, :artist, :id => "songlists_" + section.id.to_s + "_artist" %></p> 

<%= observe_field ("songlists_" + section.id.to_s + "_song_name", :update => "songlists_" + section.id.to_s + "_artist", :with => "element.value" , :url => { :controller => :songlists, :action => "get_artist" }) %> 

我有自動完成字段工作正常,並且觀察字段是根據螢火蟲觸發,但我不確定如何更新文本字段從觀察視野。Rails通過ID從auto_complete字段observe_field

我要麼需要獲得自動完成發現的ID,要麼輸入文本以便我可以將它傳遞到觀察字段的URL中。

任何想法?

回答

0

你能走過你想要這個代碼做什麼?

0

我試圖從自動完成字段獲取響應,以便用結果更新另一個文本字段。我現在的反應在螢火蟲中工作,但我似乎無法得到它與結果更新框。

<p>Song Name:<%= text_field :songlists, :song_name, :id => 
"songlists_" + section.id.to_s + "_song_name" %></p> 


<%= auto_complete_field "songlists_" + section.id.to_s + 
"_song_name",  :method => :get, 
        :with => "'search=' + element.value", 
        :url => formatted_songlists_path(:js) %> 

<p>Artist:<%= text_field :songlists, :artist %></p> 

<%= observe_field "songlists_" +section.id.to_s + "_song_name", 
        :frequency => 0.5, 
        :url => { :controller => :songlists, 
        :action => :get_artist }, 
        :update => "songlists_artist", 
        :with => "song_name" %> 

控制器代碼

def get_artist 
@songlist = Songlist.find(:all, :conditions => ['name = ?', params[:song_name]]) 

if [email protected]? 

    render :update do |page| 
    page.replace_html 'songlists_artist', :partial => 
    'get_artist', :object => @songlist 
end 

end 

end 

在Firebug我看到這個響應

try { 
Element.update("songlists_artist", "Robbie Williams"); 
} catch (e) { alert('RJS error:\n\n' + e.toString()); 
alert('Element.update(\"songlists_artist\", \"Robbie Williams\");'); 
throw e } 

但它沒有更新我的文本字段,任何想法?