Question on text_field_with_auto_complete



I have a tricky question about text_field_with_auto_complete. I’ve
created an admin section for a database of books and on each page
there is a form at the top with a single search field on the title of
books. So I’ve used:

<%= start_form_tag ({:controller => ‘books’, :action => ‘edit’ }) %>
Search Books: <%=
text_field_with_auto_complete :book, :title %>
<%= submit_tag ‘Go’ %>

This works fine except that some of the views on which this top
search bar appears are edit and create forms for books. So, they also
have input fields for :book, :title. Two unsavory results of this
are 1) The title of any book the user is editing gets inserted in the
search bar at top, rather than leaving it blank for a user to add
data and 2) If there are any validation errors on the title of a book
that a user is editing not only will the title field of the editing
form be highlighted, but also the title field in the search bar
because they are both for :book, :title, and apparently rails doesn’t
distinguish between them.

So, I tried changing the field reference of the auto_complete field
to something different:
<%= text_field_with_auto_complete :book, :searchtitle %> and in the
controller I made a custom def for the autocomplete. This seemed to
work except that whenever I go to the ‘edit’ or ‘new’ action I now
get this error:
“undefined method `searchtitle’ for #Book:0x24476a8

So it seems that the text_field_with_auto_complete has to reference a
model attribute (i.e. database field)? Only it works fine on pages
where there is no form (list views, etc). Does anyone have any idea
about what is going on here?