mapping table column primary key in the model file

A

ai

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
 
J

joey__

unknown said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top