Forum: Ruby on Rails newbie question on activerecord

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.
9eb3f9018980d0ad0feae770b2971d8b?d=identicon&s=25 DBC User (Guest)
on 2007-06-07 17:05
(Received via mailing list)
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.
0900e6a4828bd989f96427082c6c74ca?d=identicon&s=25 Mike Garey (random52k)
on 2007-06-07 17:36
(Received via mailing list)
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
9eb3f9018980d0ad0feae770b2971d8b?d=identicon&s=25 DBC User (Guest)
on 2007-06-07 17:51
(Received via mailing list)
On Jun 7, 10:36 am, "Mike Garey" <random...@gmail.com> 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.
9eb3f9018980d0ad0feae770b2971d8b?d=identicon&s=25 DBC User (Guest)
on 2007-06-07 22:36
(Received via mailing list)
On Jun 7, 10:50 am, DBC User <dbcu...@gmail.com> 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.
This topic is locked and can not be replied to.