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 collection_select(). 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Two ways the good and the bad : Good: url: /author/1/book/new BookController new @author = Author.find(params[:author_id]) @book = @author.books.new or (not so good) BookController @author = Author.find(params[:author]) @book = Book.new @book.author = @author Should work too... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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.
On 8 oct, 19:26, Freddy Andersen
<fre...-RCI/mp9mI1I6GGFevw1D/A@public.gmane.org>
wrote:> Two ways the good and the bad :
>
> Good:
>
> url:
> /author/1/book/new
>
> BookController
> new
> @author = Author.find(params[:author_id])
> @book = @author.books.new
>
> or (not so good)
>
> BookController
>
> @author = Author.find(params[:author])
> @book = Book.new
> @book.author = @author
>
> Should work too...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I''ve managed to do it the old way using /books/new?author_idand @author = Author.find(params[:author_id]) @book = @author.books.new as you''ve suggested. thanks again. On 9 oct, 02:48, robertderosny <robertdero...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On 8 oct, 19:26, Freddy Andersen <fre...-RCI/mp9mI1I6GGFevw1D/A@public.gmane.org> wrote: > > > Two ways the good and the bad : > > > Good: > > > url: > > /author/1/book/new > > > BookController > > new > > @author = Author.find(params[:author_id]) > > @book = @author.books.new > > > or (not so good) > > > BookController > > > @author = Author.find(params[:author]) > > @book = Book.new > > @book.author = @author > > > Should work too...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---