Forum: Ruby on Rails Foreign keys not showing!

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3dda2c76123692d982b648851f710269?d=identicon&s=25 Bealach Na Bo (Guest)
on 2006-04-04 19:35
(Received via mailing list)
I'm new at this so please be patient.

I have a very simple schema consisting of a around 10 tables in
Postgresql. The aim is to provide a system for PC administrators to
keep track of PC's dotted around various venues (shops, libraries
etc.). The sort of info I want to store is PC specs, PC network specs,
PC ownership specs, PC location specs and contact person details. So I
end up with a few tables associated with one another through foreign
keys and join tables. Two of the tables, for example, are created
with (nodes are PC's):

Create table "shops"
    "id" Serial NOT NULL,
    "name" Varchar(20) NOT NULL,
    "street" Varchar(20),
    "zip" Varchar(20),
    "city" Varchar(20),
    "phone" Varchar(20),
    "contact" Varchar(20),
    "hours" Varchar(20),
 primary key ("id")
) With Oids;

Create table "nodes"
    "id" Serial NOT NULL,
    "shop_id" Integer NOT NULL,
    "name" Varchar(20),
    "ip" Varchar,
 primary key ("id")
) With Oids;

Alter table "nodes" add  foreign key ("shop_id") references "shops"
on update restrict on delete restrict;

Now I want rails to present a form for registering a new node - that is
specs and which shop it belongs to. So I

$> ruby script/generate scaffold Node Admin
$> ruby script/generate model Shop

and edited <Application root>/app/models/node.rb to read

class Node < ActiveRecord::Base
  belongs_to :shop

But when I go to http://localhost:3000/admin/new
the shop_id field is not one of the fields.

I've obviously not understood how much automation can be expected from
Rails. Any comments and pointers would be much appreciated.

Warm regards,

89d967359903c639d31e4cad4569f537?d=identicon&s=25 Charlie Bowman (Guest)
on 2006-04-04 19:38
(Received via mailing list)
You can always edit the .rhtml files to include any fields that are not
showing.  By default the primary fields and foreign key aren't shown
when you scaffold a table.
3dda2c76123692d982b648851f710269?d=identicon&s=25 Bealach Na Bo (Guest)
on 2006-04-04 20:09
(Received via mailing list)
Thanks Charlie. I guess I was hoping to get away with a bit less work. I
don't suppose there is a way of telling Rails to create the scaffold for
things like "create shop if it does not exit" and then write the code
taking the user to a "shop registry" page.

This topic is locked and can not be replied to.