# Newbie question on activerecord

**URL:** <https://www.ruby-forum.com/t/newbie-question-on-activerecord/106216>\
**Category:** Rails\
**Created:** [June 7, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/newbie-question-on-activerecord/106216 "2007-06-07T17:05:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DBC\_User](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@DBC\_User](https://www.ruby-forum.com/u/DBC_User)\
**Post date:** [June 7, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/newbie-question-on-activerecord/106216/1 "2007-06-07T17:05:45Z")

</div>

I am an new to Rails. I created a simple web app called test and  
database called test with ‘People’ table. Then I did scaffold of  
Person and everything is fine. I was able to go to the index page and  
from there I was able to create a new person. After creating it went  
back to index and from there I clicked the ‘edit’ and I got  
activerecord::recordnotfound  
I didn’t make any changes to the default code generated for me.

Could someone tell me what could be wrong?

Thanks.

---

<div class="post-metadata">

**Author:** ![DBC\_User](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@DBC\_User](https://www.ruby-forum.com/u/DBC_User)\
**Post date:** [June 7, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/newbie-question-on-activerecord/106216/2 "2007-06-07T17:36:50Z")

</div>

take a look at the edit method in your controller, it should look  
something like:

Person.find(params[:id])

make sure that params[:id] is not empty, since find will raise a  
recordnotfound exception if it can’t return any records (you can use  
find\_by\_id to avoid raising an exception in the event of no matching  
records found, although usually you’ll want to make sure you handle  
either case programmatically).

Mike

---

<div class="post-metadata">

**Author:** ![DBC\_User](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@DBC\_User](https://www.ruby-forum.com/u/DBC_User)\
**Post date:** [June 7, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/newbie-question-on-activerecord/106216/3 "2007-06-07T17:51:53Z")

</div>

On Jun 7, 10:36 am, “Mike G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Person and everything is fine. I was able to go to the index page and  
> > from there I was able to create a new person. After creating it went  
> > back to index and from there I clicked the ‘edit’ and I got  
> > activerecord::recordnotfound  
> > I didn’t make any changes to the default code generated for me.
> 
> > Could someone tell me what could be wrong?
> 
> > Thanks.- Hide quoted text -
> 
> - Show quoted text -

Thanks and yes the code is correct and as I said before I didn’t touch  
the code at all. I was just trying to see how the scaffold works so I  
didn’t change anything on the code.

---

<div class="post-metadata">

**Author:** ![DBC\_User](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@DBC\_User](https://www.ruby-forum.com/u/DBC_User)\
**Post date:** [June 7, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/newbie-question-on-activerecord/106216/4 "2007-06-07T22:36:37Z")

</div>

On Jun 7, 10:50 am, DBC User [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > I am an new to Rails. I created a simple web app called test and
> 
> > - Show quoted text -
> 
> Thanks and yes the code is correct and as I said before I didn’t touch  
> the code at all. I was just trying to see how the scaffold works so I  
> didn’t change anything on the code.- Hide quoted text -
> 
> - Show quoted text -

Found the problem. In my table the primary key had a different name  
then id. When I change the primary key of the table to id everything  
worked.
