I am trying to set a default value for a text field used for a search, which uses the observe method. Here's what I got which works.
<% 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 %>
This works fine, but obviously the value is nil.
Now if I add in the value like so:
<% 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 %>
An exception is thrown.
Any idea on how I can get a default value for this text field?
Thank you.
Do not use :value => 'test'
, simply use 'test'
:
<%= text_field_tag 'phrase', 'test' %>
The format you tried to use is for text_field
helper that is usually coming from a model, text_field_tag
does not typically come from a model.
精彩评论