On Sat, Oct 2, 2010 at 8:47 PM, nobosh <[email protected]> wrote:

> Hello,
>
> I have the following Rails3 nested resource in my routes.rb:
>
>    resources :books do
>      resources :authors
>    end
>
> My authors table has ID | name | book_id
>
> Given I'm at the URL /books/312/authors/new
>
> I'm having problems getting a new author created for the book....
>
> Here's my authors controller code:
>
> def create
>        @books = Book.find(params[:book_id])
>        @author = @book.authors.create(params[:note])
> .
>
this should look like this

def create
       @books = Book.find(params[:book_id])
       @author = @book.authors.build(params[:author])
        if @autho.save
       blah blah ....

what  you have makes no sense




> .
> .
> end
>
> My NEW FORM (which I think is the problem, looks like this:
>
> <%=form_for [...@book , @author] do |f| %>
> .
> .
> .
>
for this to work in the new action in the controller you must have created
@book and @author like this

def new

@book = Book..find(params[:book_id])
@author = @book.authors.new

if you dont then this [...@book , @author]  gets book as nil



>
>  <div class="actions">
>    <%= f.submit %>
>  </div>
> <% end %>
>
>
> When I submit I get the ERROR:
> "Couldn't find Book without an ID"
> And the URL changes to "/books/ & NOT  /books/312/authors  ... as
> expected
>

post what you do after save, it appears something is wrong in the render
:action => :new section of the create action



>
> Suggestions? Thank you
>
> --

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to