I'm creating a very simple Rails app that will become my online phone book. I just want to scaffold the whole thing as much as possible since I don't need anything fancy.
I have a People table, and a Phone_Numbers table in my db. Phone_Numbers has a person_id field.
Here's my Person class:
class Person < ActiveRecord::Base
has_many :phone_numbers
end
and my PhoneNumber class:
class PhoneNumber < ActiveRecord::Base
belongs_to :person
end
However, when I run the scaffolding, I cannot add/edit phone numbers when I edit a Person. Is this normal? I thought scaffolding would do this automatically, but maybe I was expecting too much from this.
Thanks!
People succeed in answering Carl Mercier's questions 23% of the time (5 successes in 22 attempts).
Answers by: Dave
I think you're expecting too much from scaffolding...basically it (1) shows you snapshots of your table and (2) allows individual record editing within one table.
However, I think you can still get the effect you want if you instead include all the different phone number types as separate fields in a the person table. That is, drop the phone number table and add "cell phone", "fax number", "home phone", "office phone", etc. as fields in the Person table.
If this phone book is as simple as you indicate, this should be adequate. Moreover, it will allow you to do all your editing on a single page using the default scaffolding.
Hi Dave,
I guess I was expecting to much form Scaffold :) I don't want to drop the phone_numbers table for a few reasons, however...
Hi Carl,
I came across something else that might help: the Scaffolding Extensions Plugin. It seems to provide drop-down lists for your "belongs to" associations, and allows you to add entries for the "has many" associations. It may not provide the perfect solution, but it will probably beat the default scaffolding.
More about it here:
http://wiki.rubyonrails.org/rails/pages/Scaffolding+Extensions+Plugin