does not work is that the hash params for create have to be actual
attributes of the model, and not associations?
It will work. You can do it any one of the ways that were mentioned.
redhames example is of creating a phonebook when you already have a
Person;
I thought you were speaking of creating a Person when you already have a
Phonebook (pb) …? At any rate, all these example will work fine. Use
the
one that makes the most sense to you.
‘id’, that is, unless I do this:
is something more/or else messed up?
Here’s a guess, after relooking over your code above. The problem could
naming conventions.
When you say belongs_to :phonebook, Rails expects to look for a class
named
Phonebook (lowercase ‘b’), not PhoneBook
If your model is named PhoneBook, the association should be: belongs_to
:phone_book
You can override the default behavior with something like:
belongs_to :phonebook, :class_name => ‘PhoneBook’
but it’s usually easier to do things the way Rails expects them to be
done,
unless there is an important reason to use different naming conventions.
Unless your model is not really PhoneBook…? the point is, the
difference
between PhoneBook and Phonebook, and phonebook or phone_book, is
actually significant, and will cause you bugs and headaches if you
don’t
use the one rails will use by default.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.