Forum: Ruby on Rails Foreign keys not showing!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bealach Na Bo (Guest)
on 2006-04-04 21: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"
("id")
on update restrict on delete restrict;


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

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

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

class Node < ActiveRecord::Base
  belongs_to :shop
end

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,

Bealach
Charlie B. (Guest)
on 2006-04-04 21: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.
Bealach Na Bo (Guest)
on 2006-04-04 22: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
for
taking the user to a "shop registry" page.

Bealach
This topic is locked and can not be replied to.