2010-09-03 36 views
1

我想爲使用觀察方法的搜索所使用的文本字段設置默認值。這是我得到了哪些作品。RoR在使用觀察方法時爲文本字段設置默認值

<% form_tag('javascript:void(0)') do %> 
    <%= text_field_tag 'phrase', nil, {:onfocus => "$('results').show();", :onblur => "$('results').hide();"} %> 
    <%= observe_field :phrase, 
     :frequency => 0.5, 
     :update => 'results', 
     :url => {:controller => :profiles, :action => 'search', :only_path => false }, 
     :with => "'phrase=' + encodeURIComponent(value)" %> 
<% end %> 

這工作正常,但顯然價值爲零。

現在,如果我在增值,像這樣:

<% form_tag('javascript:void(0)') do %> 
    <%= text_field_tag 'phrase', :value => 'test', {:onfocus => "$('results').show();", :onblur => "$('results').hide();"} %> 
    <%= observe_field :phrase, 
     :frequency => 0.5, 
     :update => 'results', 
     :url => {:controller => :profiles, :action => 'search', :only_path => false }, 
     :with => "'phrase=' + encodeURIComponent(value)" %> 
<% end %> 

拋出異常。

任何想法如何我可以得到這個文本字段的默認值?

謝謝。

回答

3

不要使用:value => 'test',只需使用'test'

<%= text_field_tag 'phrase', 'test' %>

你試圖使用的格式是text_field幫手通常是從模型的到來,text_field_tag通常不來自模型。

+0

很酷謝謝。奇怪,雖然..在Firefox中的價值並不顯示,但在鉻和即它確實。 – Brian 2010-09-03 22:33:57

+0

沒關係。它的作品謝謝你 – Brian 2010-09-03 22:38:48

相關問題