← Back to Upcase

Difficulty figuring out how to code destroy action in Rails 4


(Jacqueline S. Homan) #1

I have not had much luck in finding any decent Rails 4.1.x tutorials out there and I started learning on Rails 3. Right now I am working on an app and got horribly stuck when trying to write the code for a simple destroy action. I got this error: I get an ActiveRecord::RecordNotFound in AlbumsController#destroy error. It’s basically saying that it couldn’t find an album with the ‘id’=Ferris Wheels.

But I DID have a Ferris Wheels album persisted to the db as my rails console shows:

And my albums controller code was correct as was the album model code. What it turned out to be was the way Rails 4 does delete and confirm methods, which is different than in Rails 3. So I had to change the code in my show template. Then I got it to work. One of the guys at the Thoughtbot campfire chat pointed me in the right direction. I would have never guessed that the problem was in my view code. Because intuitively, my first thought was that it was either in my CRUD code, or something wrong with my migrations that an album was not being persisted to the database.


(Derek Prior) #2

The output in your console shows that the album has id 5. You appear to be trying to destroy it by name.