Forum: Ruby mapping table column primary key in the model file

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.
unknown (Guest)
on 2006-03-16 22:14
(Received via mailing list)
I'm very new to RoR, and am trying to test out the scaffolding bit. I
believe there's an issue with my model file and the way I'm using
ActiveRecord, as I'm unable to show specific details of a row. The
table itself displays correctly when I do a 'list' on the webpage, but
a 'show' for a specific row doesn't work. My primary key (id) is not
called 'id', its called 'actor_id'. So, when I try to do a show, or
edit, I get the error :

ActiveRecord::RecordNotFound in Actor#show
Couldn't find Actor without an ID

How can I map my table column's primary key id (called 'actor_id') to
'id' in the model file? I've tried using 'id=actor_id', primary_key,
etc. in my model file (actor.rb) but nothing seems to work seemlessly,
unless I modify the stubs that're created when I run the ruby
script\generate scaffold.

Here's what I did to set things up :

1. I have a database called 'test', inside of which I have one table
'actors' (I don't know, just felt very hollywood-ish today). The
columns in the table are:
Actor_id (primary key)
Actor_fname
Actor_lname
Actor_address

2. modify database.yml to point to the right database, host, table etc.


3. ruby script\generate model actor

4. ruby script\generate controller actor

5. add 'scaffold:actor' to actor_controller.rb

6. ruby script\server

7. http://localhost:3000/actor

8. error occurs when I click on the 'show' link for one of the columns
: ActiveRecord::RecordNotFound in Actor#show Couldn't find Actor
without an ID

I appreciate any help you can offer. Thanks in advance,

BYT
joey__ (Guest)
on 2006-03-16 22:35
unknown wrote:
>Couldn't find Actor without an ID
>
> How can I map my table column's primary key id (called 'actor_id') to
> 'id' in the model file? I've tried using 'id=actor_id', primary_key,
> etc. in my model file (actor.rb) but nothing seems to work seemlessly,
> unless I modify the stubs that're created when I run the ruby
> script\generate scaffold.


This should really be psted on the Rails mailing
list[http://lists.rubyonrails.org/mailman/listinfo/rails]

Try:
set_primary_key 'Actor_id'

joey__
http://www.feedreed.com
This topic is locked and can not be replied to.