Rails: ActiveRecord::RecordNotFound, Couldn't find <model> with id=num

I have two models in my Ruby on Rails app: User and Bookcase. I've provided an edit link for each Bookcase, but when I click on these links, I encounter an error:

ActiveRecord::RecordNotFound in BookcasesController#edit
Couldn't find User with id=19

(Note that it's asking for the User Id. Also, it's worth noting that Bookcases belong_to Users.)

Here's the snippet I used to create the link:

<%= link_to "edit", edit_bookcase_path(bookcase.id) %>

If you need any further code, let me know and I'll post it!


From what I can tell of what you have asked, if you are in the BookcasesController in the EDIT method, you shouldn't be calling for the User, you should be calling for the BookCase, like so:

@bookcase = BookCase.find(params[:id]) // WHAT YOU WANT

It seems the you have this code instead, which is giving you the error:

@bookcase = User.find(params[:id]) // NOT WHAT YOU WANT

This will return the BookCase with the id 19, which should belong to a user. If you need to then access the user that the book belongs to, you could do so like this:

@user = @bookcase.user

Also, you can just use the edit link like to, without the id call:

<%= link_to "edit", edit_bookcase_path(bookcase) %>

Need Your Help

Devise + Facebook Omniauth Error on redirect

ruby-on-rails-3 devise omniauth facebook-authentication

I am using devise, omniauth &amp; facebook-omniauth for my Rails 3.1 app. After authentication I wanted to redirect the user to the page was viewing. I have used the following code for the same:

C# Interpretation and the GC (garbage collection) counter

c# debugging optimization garbage-collection performancecounter

The following program displays a counter that shows the load on the garbage collection.