Forum: Ruby on Rails display a form with selected values from URL

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.
robertderosny (Guest)
on 2008-10-08 19:30
(Received via mailing list)
Hi there,

I have an author model and a book model.

I'm trying to create a "add new book" link for each author from the
authors index page, that would point to a new book page, with the the
author select field already "selected" to the good option.
the author select in the new book form is created with

I don't know how to pass such a variable in a url using rails url
schema. I've looked in the link_to documentation, but nothing about
this specific case.

any help would be greatly appreciated,
thanks in advance.
Freddy A. (Guest)
on 2008-10-08 21:26
(Received via mailing list)
Two ways the good and the bad :



@author = Author.find(params[:author_id])
@book =

or (not so good)


@author = Author.find(params[:author])
@book = = @author

Should work too...
robertderosny (Guest)
on 2008-10-09 04:49
(Received via mailing list)
thanks for your help

/authors/3/books/new gives me a

Routing Error
No route matches "/authors/3/books/new" with {:method=>:get}

I guess i need to update my routes.rb for this to work ?

i've tried this :

map.resources :books, :path_prefix => "/authors/:author_id"

without success ..

if that helps : i'm using rails 2 with REST.
robertderosny (Guest)
on 2008-10-09 06:02
(Received via mailing list)
I've managed to do it the old way using /books/new?author_id=
@author = Author.find(params[:author_id])
@book =
 as you've suggested.

thanks again.
This topic is locked and can not be replied to.