Parameter for movie_path() isn't working


Technically, I've completed step 5 of 7, and the checkpoints are all green with my current code. The problem is that when I click on a "Learn more" link, I get an ActiveRecord::RecordNotFound in MoviesController#show error.

I'm not sure what the problem is. I've tried passing both :id and movie as parameters to movie_path() in the link_to link, but keep getting the same error. Does anyone have any idea as to what may be going on? My code is as follows:


<div class="main">
  <div class="container">
  <h2>Popular Films</h2>
    <% @movies.each do |movie| %>
    <div class="movie">
      <%= movie.image %>
      <h3> <%= movie.title %> </h3>
      <p> <%= movie.release_year %> </p>
      <%= link_to "Learn more", movie_path(movie) %>
   <% end %>      


def show
    @movie = Movie.find(params[:id])
    @actors = @movie.actors


get '/movies/:id' => 'movies#show', as: :movie


Hi @ams45943,

Your code is fine. Leave it the way it is, but use a numerical id, rather than the word itself. For example, https://localhost/movies/1 :slight_smile:


That did work. What I'm wondering, though, is why the :id of the movie tied to each link isn't getting passed to the url automatically. Unless there's something that's supposed to be doing that in the code, but isn't covered in step 5. Essentially, instead of having to enter the number in manually, just clicking on the "Learn more" link should do that. Although I may be getting ahead of myself.

EDIT: Funnily enough, when I moved on to step 6 and finished hooking up everything for displaying the actors and getting a list of movies through each actor, the rest of the app started working as it should (could click on the "Learn more" link under a movie and I'd go the the page for that movie).


That's interesting. I'm glad you got it to work, though :slight_smile:


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.