Autocomplete input field name


#1

Hi All,

I’m new to ruby on rails and I struggle with a problem in my first
application. I searched the forum (and ofcourse google) but I think it
is just an easy thing that nobody boughters to write down :slight_smile:

I am building a kind of library application for (fysical) books and
e-books and later I want to add other functions like knowledge
management.

The problem: in the book show page I have a form to add a author with
auto complete:

show.rhtml

<%= text_field_with_auto_complete :author, :name %> ...

book_controller.rb
class BookController < ApplicationController
auto_complete_for :author, :name, :limit => 5

def addauthor
@book = Book.find(params[:bookid])
@author = Author.find_by_name(params[:authorname])
@book.authors.push(@author)
redirect_to :controller => ‘book’, :action => ‘show’, :id => @book
end

When I manually enter the right url with variabels (is it english?)
bookid and authorname it works, but when I use the form the name of the
autocomplete field is author[name] and the url it produces is:

http://localhost:3000/book/addauthor?author[name]=a4&bookid=1&Submit=Submit

So I get an error and I cannot say @author =
Author.find_by_name(params[:author[name]])

All help is welcome,

With kind regards,

Alexander Ketelaar
removed_email_address@domain.invalid


#2

I already found it:

@author = Author.find_by_name(params[:author][:name])

Thanx anyway