I followed the RailsCasts tutorial to do a simple search with autocomplete, but it doesn't work. :(
view/vendors/index:
<% form_tag vendors_path, :method => 'get' do %>
<%= text_field_with_auto_complete :vendor,
:name,
{},
{:method => :get, :class => 'textbox'} %>
<%= submit_tag "Search", :name => nil %>
<% end %>
</div>
<%= @searchvendor.id %>
<%= @searchterm %>
I included @searchterm and @searchvendor.id as validation steps.
So this should call the controller => vendor, action=> index:
def index
@searchterm = params[:vendor][:name]
@searchvendor = Vendor.search('checkpoint')
And the search method is created as follows for the vendor/model:
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
The output?
@searchterm does show the value that is inputed as that shows up in the URL as vendor[name]=?
@searchvendor.id is a long string and @searchvendor.name shows an error, name not a method.
I'm stumped. Help...please?
LINK to the Tutorial: