Forum: Ruby on Rails question on text_field_with_auto_complete

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-02-18 04:48
(Received via mailing list)

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' }) %>
<label for="book_title">Search Books: </label><%=
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?

This topic is locked and can not be replied to.