Reputation: 8189
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!
Upvotes: 0
Views: 1045
Reputation: 1137
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) %>
Upvotes: 2