this should solve the java.net.BindException: Address already in use: JVM_Bind
happy deployment :)
<%= link_to "#{h(item.first_name)}'s stuff", :action => :view, :id => item %>
<%= link_to "#{item.first_name}'s stuff", :action => :view, :id => item %>
This example will auto-populate a state and postcode based on the user's selected suburb
The first step is to create a view for the page containing the autocomplete field and for the autocomplete field itself.
Controller:
def new
# This is the main controller that will
# contain the autocomplete field
@contact = Contact.new
end
def auto_complete_for_suburb
suburb = params[:suburb]
@surburbs = Suburb.find_by_name(suburb,
:order => "name", :limit => 20)
render :partial => "auto_complete_suburb"
end
View for the new action (assume an application.rhtml template has been created, this template must include the Prototype and Script.aculo.us javascript libraries):
<%= form_tag({:action => :create}, {:method => :post}) %>
Name:
<%= text_field(:contact, :name) %>
Suburb:
<%= text_field_with_autcomplete(:contact, :suburb,
:select => "value",
:after_update_element =>
"function (ele, value) {
$("contact_state").value =
Ajax.Autocompleter.extract_value(value,
'STATE');
$("contact_postcode").value =
Ajax.Autocompleter.extract_value(value,
'POSTCODE'); }
") %>
State:
<%= text_field(:contact, :state, :size => 10) %>
Postcode:
<%= text_field(:contact, :postcode,
:size => 10) %>
<%= end_form_tag %>
Before we continue any further, it is worth-while defining the _auto_complete_suburb.rhtml partial.
<% unless @suburbs.nil? -%>
<% @suburbs.each do | suburb | -%>
<%= h("#{suburb[:name]}, #{suburb[:state]}" +
"#{suburb[:postcode]}") %>
<%= h(suburb[:name]) %>
<%= h(suburb[:state]) %>
<%= h(suburb[:postcode]) %>
<% end -%>
<% end -%>
The autocompleter view has three (3) hidden
You may also want to cast your eye over the suburb field definition in the new contact view as this is where most of the action is. There are two options to note:
The Script.aculo.us Autocompleter methods conviently pass the complete contents of the
Additional method for Ajax.Autocompleter class. This can be declared anywhere after the inital Script.aculo.us script inclusion. For my purposes I put this at the top of my application.js file.
Ajax.Autocompleter.extract_value =
function (value, className) {
var result;
var elements =
document.getElementsByClassName(className, value);
if (elements && elements.length == 1) {
result = elements[0].innerHTML.unescapeHTML();
}
return result;
};