ruby on rails - undefined method `movie_reviews' for nil:NilClass -
i made simple test app reviewing movies. error throughout application. i've set inheritance in models (using api movie data) , other standard things, don't know why i'm getting error. example, visiting url -
...movies/%23<tmdb::movie:0x00000002d30728>/movie_reviews/new
i error
app/controllers/movie_reviews_controller.rb:17:in `new' def new @movie_review = @movie.movie_reviews.new end
here's source code on gh: https://github.com/xantax/sample_movies
you never set instance variable @movie
in new action of controller. every instance variable returns nil if hadn't been set before. @movie
nil , expected you'll error.
another thing should pay attention url. url path should have numeric movie id instead of %23<tmdb::movie:0x00000002d30728>
. may prevent finding movie you'd in controller easily. if had been 23 example simply:
@movie = movie.find(params[:id])
because /movies/23/more_reviews/new puts 23 params[:id]
hope helps figure out problem.
Comments
Post a Comment