Forum: Ruby on Rails autocomplete input field name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alexander K. (Guest)
on 2006-02-13 15:37
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 :)

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
...
  <form action="/book/addauthor" method="get">
  <%= text_field_with_auto_complete :author, :name %></p>
  <input name="bookid" value="<%= @book.id %>" type="hidden">
...

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%5Bname...

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
Alexander K. (Guest)
on 2006-02-13 22:44
I already found it:

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

Thanx anyway
This topic is locked and can not be replied to.