If you're going to follow Rails convention, go back to author_id. Through AR magic, when you say "book belongs to author," it automagically gives some methods to your book model. One of those is "author" which it expects to return a Author model object found using the author_id attribute as a foreign key. That's why you're getting the mismatch error. I'm assuming when it's author_id, that field is not going to show up in scaffolding b/c rails knows that's a foreign_key and not a regular attribute (like name or title or something).

Going back to the original issue, did you try my suggestion on the form_for syntax? The doc examples show passing both the symbol and instance variable like this:

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

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

Thank you for the replies-I don't think I'm being clear about the core problem, though.

I have no need for anything more flexible than the scaffold for this-it's an admin-only data entry form. I'm also very new at this, so abstract advice and code snippets don't help me because I have no context for them.

What I need is simply this:

A form that writes to the BOOKS table that includes an integer field for "author_id" (or simply "author" - see below). I can pretty it up with a select field of author names later. The BASIC function of the form still doesn't work.

The problem DOES seem to be with the _id extension of the field. When I rebuild the table and rename the field "author" instead of "author_id" the field shows up correctly in the scaffold form.

HOWEVER, now, I can't write to the table because I get an error of "Association TypeMismatch" in the BooksController: Author expected, got String

I think the issue is that the text field for "author" is not sending as an integer, which is what the "author" field in the database is. Actually, I'm sure of this, because in the session dump the request parameters show:

"author" => "1" when it SHOULD show "author" => 1

How can I fix this?
--
***************************************
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