views:

456

answers:

1

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:

http://railscasts.com/episodes/37-simple-search-form

+3  A: 
  1. Should you not be passing in your @searchterm into your Vendor.search method? Passing 'checkpoint' each time probably isn't going to do the trick.

  2. @searchvendor is going to contain an Array as you are doing find(:all). You'll need to iterate over the array and do .name on each item.

RichH
right, it was passing it -- I changed it and cut/paste wrong code to do a sanity check...however, #2 seems like what is the problem...!! Will try that out first!
Angela
okay, I am passing params[:name] and tried params[:vendor][:name] which seemed to make sense but that bombed.
Angela
Bombed in what way? Have you used a debugger (like the one in Netbeans) to check the value of params[:name], params[:vendor][:name] or just params?
RichH