I think your form_for method needs to look like this:

form_for :book, @book, :url => { :action => create } do |form|

On Feb 22, 2007, at 10:05 AM, Kevin Burk wrote:

I'm still having problems with forms to create new objects.

The model is this: I have an AUTHORS table and a BOOKS table. I want a form where I can log in and create new BOOKS. Each BOOK has a foreign key of "author_id" which lives in the BOOKS table, but is connected in the models to the AUTHORS table.

When I create a static scaffold for the BOOKS to create a new BOOK, the "author_id" field does not show up in the scaffold form. Obviously, I need to be able to specify the author of the book or there's not much point in creating the book.

I've tried manually editing the code and adding in an "author_id" form field but it never displays.

I've tried scrapping the whole scaffold form and under the "New" view/action, creating a form using

<% form_for :book, :url => { :action => :create} do |form| %>
<p> Author ID: <%= form.text_field :author_id, :size => 4 % ></p>
        <p> Title: <%= form.text_field :title, :size => 30 %></p>
<p> Description: <%= form.text_area :description, :rows=> 4 %></p>
<p><%= submit_tag %> </p>
<% end %>


as detailed in AWDR2.

This doesn't work.

I get error messages saying "undefined method 'title' ".

IF I change the first line of code to:

<% form_for :books, :url => { :action => :create} do |form| %>

(:books, not :book)

The form displays correctly, but the new records aren't created.

Where's the disconnect here? Apparently, Rails doesn't like having a foreign key constraint placed on the "author_id" field in the Books table. Is this just because of the _id part of the field name?

Thanks for your help.

Kevin Burk
--
***************************************
BURK DESIGN GROUP
http://www.BurkDesignGroup.com
mailto:[EMAIL PROTECTED]
6161 El Cajon Blvd #306
San Diego, CA 92115
PHONE (619) 583-2311
FAX (619) 583-5801
***************************************
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to