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.
DBC User (Guest)
on 2007-06-07 19: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.
Mike G. (Guest)
on 2007-06-07 19: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
DBC User (Guest)
on 2007-06-07 19:51
(Received via mailing list)
On Jun 7, 10:36 am, "Mike G." <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.
DBC User (Guest)
on 2007-06-08 00:36
(Received via mailing list)
On Jun 7, 10:50 am, DBC User <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.
This topic is locked and can not be replied to.