Saturday, October 2, 2010

[Rails] Re: Nested Resourced, Books > Authors… Creating Records for Authors…

Updated the author controller with:

def new
@note = Author.new
@book = Book.find(params[:book_id])
.
.
end

Now the form is creating what seems like the right URL:
<form accept-charset="UTF-8" action="/books/3/authors"
class="new_author" id="new_author" method="post">
...

But after submitting a new author, it errors with (after hanging for a
while locally):
SQLite3::BusyException: database is locked: INSERT INTO
"authors" .........


thanks


On Oct 2, 11:47 am, nobosh <bhellm...@gmail.com> 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])
> .
> .
> .
> end
>
> My NEW FORM (which I think is the problem, looks like this:
>
> <%=form_for [@book , @author] do |f| %>
> .
> .
> .
>
>   <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
>
> 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate