I can’t get the autocomplete feature of script.aculo.us to work. I
have tried every guide I could find and several books to no avail.
As you can probably tell from the code, I’m new to this and just used
the scaffolding feature to setup a framework I was planning on
altering. Things I’ve tried so far to no avail are removing the
auto_complete function from the controller and removing the
javascript_include_tag from the view. Regardless of those changes,
when I type the first letters of a valid name into the
text_field_with_auto_complete it does not give me any suggestions. Any
help would be most appreciated!
Below are excerpts from my controller and my view file:
##########################
#ErrorsController
##########################
class ErrorsController < ApplicationController
auto_complete_for :error, :name
GET /errors
GET /errors.xml
def index
@errors = Error.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @errors }
end
end
GET /errors/1
GET /errors/1.xml
def show
@error = Error.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @error }
end
end
GET /errors/new
GET /errors/new.xml
def new
@error = Error.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @error }
end
end
GET /errors/1/edit
def edit
@error = Error.find(params[:id])
end
POST /errors
POST /errors.xml
def create
@error = Error.new(params[:error])
respond_to do |format|
if @error.save
flash[:notice] = 'Error was successfully created.'
format.html { redirect_to(@error) }
format.xml { render :xml => @error, :status
=> :created, :location => @error }
else
format.html { render :action => “new” }
format.xml { render :xml => @error.errors, :status
=> :unprocessable_entity }
end
end
end
PUT /errors/1
PUT /errors/1.xml
def update
@error = Error.find(params[:id])
respond_to do |format|
if @error.update_attributes(params[:error])
flash[:notice] = 'Error was successfully updated.'
format.html { redirect_to(@error) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @error.errors, :status
=> :unprocessable_entity }
end
end
end
DELETE /errors/1
DELETE /errors/1.xml
def destroy
@error = Error.find(params[:id])
@error.destroy
respond_to do |format|
format.html { redirect_to(errors_url) }
format.xml { head :ok }
end
end
end
#######################
#index.html.erb
#######################
Listing errors
<%= javascript_include_tag :defaults %> <%= text_field_with_auto_complete :error, :name %> <% for error in @errors %> <% end %>Name | Description | Solution | |||
---|---|---|---|---|---|
<%=h error.name %> | <%=h error.description %> | <%=h error.solution %> | <%= link_to 'Show', error %> | <%= link_to 'Edit', edit_error_path(error) %> | <%= link_to 'Destroy', error, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to ‘New’, new_error_path %>
#######################