Topic: Autocomplete issue after changes to table

I used to have a working autocomplete feature in my app using:

  def auto_complete_for_search_
    @items = Item.find(:all, :conditions => ['name LIKE ?',
                 '%' + params[:search].to_s + '%'])
    render :inline => "<%= auto_complete_result(@items, 'name') %>"
  end

However, I decided to move the 'name' attribute out of the items-table and put it in an 'itemstats'-table.
So I changed the first line into:

  @items = Item.find(:all, :include => :itemstat, 
    :conditions => ['name LIKE ? AND open = ?', '%' + params[:search].to_s + '%', true])

But I am clueless as to how I can get the 'name' attribute to show in the result. I attempted things like 'itemstat.name', but that didn't work.

Re: Autocomplete issue after changes to table

Vithu wrote:

I used to have a working autocomplete feature in my app using:

  def auto_complete_for_search_
    @items = Item.find(:all, :conditions => ['name LIKE ?',
                 '%' + params[:search].to_s + '%'])
    render :inline => "<%= auto_complete_result(@items, 'name') %>"
  end

However, I decided to move the 'name' attribute out of the items-table and put it in an 'itemstats'-table.
So I changed the first line into:

  @items = Item.find(:all, :include => :itemstat, 
    :conditions => ['name LIKE ? AND open = ?', '%' + params[:search].to_s + '%', true])

But I am clueless as to how I can get the 'name' attribute to show in the result. I attempted things like 'itemstat.name', but that didn't work.

have you tried

<% for item in @items %>
  <%= item.itemstat.name %>
<% end %>

--jake

---------------------------------------------------------------------
Rails Development - Agile rails consulting and development for startups on a budget
Flvorful Blog - Some ramblings
Flvorful's Open Source Projects - Some handy hacks for your rails projects.

Re: Autocomplete issue after changes to table

Thanks, but that didn't work.
I figured it out. Reworked the first line some more, so I didn't have to rewrite the second after all.

 def auto_complete_for_search_
   @items = Itemstat.find(:all, :include => :items,
       :conditions => ['open = ? AND name LIKE ?', true, '%' + params[:search].to_s + '%'])
   render :inline => "<%= auto_complete_result(@items, :name ) %>"
end