Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
ActiveRecord::RecordNotFound in ReviewsController#index
3 Posts
ActiveRecord::RecordNotFound in ReviewsController#index

I do have the feeling that the answer is probably something very simple. I'm still trying to get my arms around how to properly write and perform and interpret the results of tests, and I suppose now is the best time to learn. :-)

Going to check and make sure that I have the proper rows in db's as well. And thanks for the tip on properly formatting my example code. Cracking open my simply rails 2 book again :-)

Thanks for the help

You get an ActiveRecord::RecordNotFound exception when you try to find a row in the database that doesn't exist. At some point you're executing a #find call of some kind, with, presumably, an invalid ID.

It's possible that the problem is relatively simple and you simply need to check the IDs that your controllers receive before trying to find them. It's also possible that some of your ActiveRecord objects are trying to load associated objects which don't exist; either because you have invalid data loaded from fixtures, or because something deleted a row leaving a dangling reference, or something else entirely.

To be honest, the easiest and best way to track down problems like this is to make sure you comprehensively test your controllers as you're writing them.

Also, on an unrelated note, your example code will be easier to read in these posts if you wrap it in <pre> tags. Like so:

class Movie < ActiveRecord::Base
  ...
end
...

I'm building my first ROR application and having a problem with new controller. I've created the Reviews controller with associated views and established a belongs_to relationship with another controller. I'm getting the above error when trying to load the page. Any ideas what I'm doing wrong? Code included below.

movie.rb class Movie < ActiveRecord::Base validates_presence_of :title, :director, :genre, :release, :rating, :synopsis has_many :reviews, :dependent => :destroy has_many :tags

accepts_nested_attributes_for :tags, :allow_destroy => :true,

:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }

end

review.rb class Review < ActiveRecord::Base belongs_to :movie has_many :votes has_many :photos ...

routes.rb ActionController::Routing::Routes.draw do |map| map.resources :movies, :has_many => :reviews map.resources :photos map.resources :users, :has_many => :photos map.resources :reviews map.resources :reviews, :belongs_to => :movies map.resources :reviews, :has_many => [:votes, :photos] map.resources :votes, :belongs_to => :reviews

3 Posts
Login to add your message